Ir para conteúdo
Fórum Script Brasil

ruan0408

Membros
  • Total de itens

    3
  • Registro em

  • Última visita

Sobre ruan0408

ruan0408's Achievements

0

Reputação

  1. Solução dada no Stackoverflow: It looks to me from the API documentation (albeit, I can't read Portugese), that the token needs to be in the URL, not POSTed to it: POST /Login/Autenticar?token={token} I think you are POSTing a form to this endpoint. You should try this: String targetURL = "http://api.olhovivo.sptrans.com.br/v0/Login/Autenticar?token=3de5ce998806e0c0750b1434e17454b6490ccf0a595f3884795da34460a7e7b3"; And don't call post.setEntity(...).
  2. Estou tentando fazer um wrapper para a API olho vivo, da SPtrans http://www.sptrans.com.br/desenvolvedores/APIOlhoVivo/Documentacao.aspx?1#docApi-autenticacao Estou usando a biblioteca apache commons para fazer as requisições POST. Por algum motivo estou recebendo Error 404, No HTTP resource was found that matches the request URI 'http://api.olhovivo.sptrans.com.br/v0/Login/Autenticar'. Pensei que talvez a API não estivesse funcionando, mas achei esse wrapper em python https://gist.github.com/jonathansp/7491340 e testei ele com a minha chave de liberação e tudo funcionou. Essa é a função que executa o POST. public static String executePost() { CloseableHttpClient client = HttpClientBuilder.create().build(); String targetURL = "http://api.olhovivo.sptrans.com.br/v0/Login/Autenticar"; List<NameValuePair> urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair("token","3de5ce998806e0c0750b1434e17454b6490ccf0a595f3884795da34460a7e7b3")); try { HttpPost post = new HttpPost(targetURL); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse response = client.execute(post); System.out.println("Response Code : " + response.getStatusLine().getStatusCode()); BufferedReader rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) result.append(line); System.out.println(result.toString()); return result.toString(); } catch (Exception e) { e.printStackTrace(); return null; } } Isso é o que é printado: Response Code : 404 {"Message":"No HTTP resource was found that matches the request URI 'http://api.olhovivo.sptrans.com.br/v0/Login/Autenticar'."}
  3. Estou tentando fazer um wrapper para a API olho vivo, da SPtrans http://www.sptrans.com.br/desenvolvedores/APIOlhoVivo/Documentacao.aspx?1#docApi-autenticacao Estou usando a biblioteca apache commons para fazer as requisições POST. Por algum motivo estou recebendo Error 404, No HTTP resource was found that matches the request URI 'http://api.olhovivo.sptrans.com.br/v0/Login/Autenticar'. Pensei que talvez a API não estivesse funcionando, mas achei esse wrapper em python https://gist.github.com/jonathansp/7491340 e testei ele com a minha chave de liberação e tudo funcionou. Essa é a função que executa o POST. public static String executePost() { CloseableHttpClient client = HttpClientBuilder.create().build(); String targetURL = "http://api.olhovivo.sptrans.com.br/v0/Login/Autenticar"; List<NameValuePair> urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair("token","3de5ce998806e0c0750b1434e17454b6490ccf0a595f3884795da34460a7e7b3")); try { HttpPost post = new HttpPost(targetURL); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse response = client.execute(post); System.out.println("Response Code : " + response.getStatusLine().getStatusCode()); BufferedReader rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) result.append(line); System.out.println(result.toString()); return result.toString(); } catch (Exception e) { e.printStackTrace(); return null; } } Isso é o que é printado: Response Code : 404 {"Message":"No HTTP resource was found that matches the request URI 'http://api.olhovivo.sptrans.com.br/v0/Login/Autenticar'."}
×
×
  • Criar Novo...