I have a web API running with a service called Authorize.
Authorize takes 1 parameter (called ) and returns a different key.
I'm going to call this from a Java application. I've done
public static void main(String[] args0)
{
HttpClient httpClient = HttpClientBuilder.create().build();
try{
HttpPost request = new HttpPost("http://localhost:50481");
StringEntity params = new StringEntity("Authorize={\"auth\":\"123456\"}");
request.addHeader("content-type", "application/json");
request.addHeader("Accept", "application/json");
HttpResponse response = httpClient.execute(request);
JSONObject json = new JSONObject(response);
System.out.println(json);
}
catch(Exception ex){
System.out.println(ex.toString());
}
finally{
}
}
The problem is, that the System.out.println(json);
only returns an empty object: {}
Does that mean that there is a problem in the service itself, or that it does not hit a valid method on the API?
由于{}
是有效的(空)json,因此您不会遇到任何异常,就好像您的服务返回带有空json对象的响应一样。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.