Jump to content
Fórum Script Brasil
  • 0

Erro ao fazer requisição POST


ruan0408
 Share

Question

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'."}

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      149.6k
    • Total Posts
      646.2k
×
×
  • Create New...