Java 使用apache commons的响应代码404

Java 使用apache commons的响应代码404,java,apache,http,http-status-code-404,Java,Apache,Http,Http Status Code 404,我正在为一个API构建一个包装器(它是葡萄牙语的,但是你明白了) 我在发出POST请求时收到了404响应代码,我不知道为什么 这就是正在打印的内容: 响应代码:404{“Message”:“未找到该消息的HTTP资源。” 匹配请求URI ''。} 公共静态字符串executePost(){ CloseableHttpClient客户端=HttpClientBuilder.create().build(); 字符串targetURL=”http://api.olhovivo.sptrans.com

我正在为一个API构建一个包装器(它是葡萄牙语的,但是你明白了)

我在发出POST请求时收到了404响应代码,我不知道为什么

这就是正在打印的内容:

响应代码:404{“Message”:“未找到该消息的HTTP资源。” 匹配请求URI ''。}

公共静态字符串executePost(){
CloseableHttpClient客户端=HttpClientBuilder.create().build();
字符串targetURL=”http://api.olhovivo.sptrans.com.br/v0/Login/Autenticar";
List urlParameters=new ArrayList();
添加(新的BasicNameValuePair(“令牌”,“3DE5CE998806E0C0750B1434E17454B6490CCF0A595F3884795DA34460A7B3”);
试一试{
HttpPost=新的HttpPost(targetURL);
setEntity(新的UrlEncodedFormEntity(urlParameters));
HttpResponse response=client.execute(post);
System.out.println(“响应代码:
+response.getStatusLine().getStatusCode());
BufferedReader rd=新的BufferedReader(
新的InputStreamReader(response.getEntity().getContent());
StringBuffer结果=新的StringBuffer();
字符串行=”;
而((line=rd.readLine())!=null)result.append(line);
System.out.println(result.toString());
返回result.toString();
}捕获(例外e){
e、 printStackTrace();
返回null;
}
}

从API文档(尽管我不懂葡萄牙语)来看,令牌需要在URL中,而不是发布到URL中:

POST/Login/Autenticar?token={token}

我认为您正在向该端点发布表单

你应该试试这个:

String targetURL = "http://api.olhovivo.sptrans.com.br/v0/Login/Autenticar?token=3de5ce998806e0c0750b1434e17454b6490ccf0a595f3884795da34460a7e7b3";

不要调用
post.setEntity(…)

就是这样!我认为post方法的要点就是不使用url。我不知道你可以“什么都不发”。这是我第一次处理这件事。无论如何,非常感谢!!
String targetURL = "http://api.olhovivo.sptrans.com.br/v0/Login/Autenticar?token=3de5ce998806e0c0750b1434e17454b6490ccf0a595f3884795da34460a7e7b3";