While working on a Micro-Service, I have to hit the REST OAuth api of the 3rd party. I am using the Spring Boot Application with Jersey library. Now the problem is that I am getting 400 response every-time from my java code.
If I hit the same call using the REST client, I get the 200 response code and desired response as well. Why so ?
以下是相同的Java源代码 -
@Produces("application/json")
@POST
@Path("/endPoint")
@Consumes("application/x-www-form-urlencoded")
public JSONObject getAccessToken(@FormParam("item1") String item1,@FormParam("item2") String item2,@FormParam("item3") String item3,@FormParam("item4") String item4) throws Exception {
System.out.println("Enter to test");
String extendedUrl = "?item1="+item1+"&item2="+item2+"&item3="+item3+"&item4="+item4;
JSONObject jObject = null;
try {
jObject = postCall(extendedUrl);
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Box Auth Response :: "+jObject.toJSONString());
return jObject;
}
//执行请求的逻辑的简短描述
public void postCall(String extendedUrl)
{
String url = "baseurl";
url+=extendedUrl;
HttpsURLConnection conn = openConnection(apiUrl);
conn.connect();
status = conn.getResponseCode();
String responseContentType = conn.getContentType();
System.out.println("responseContentType ::"+responseContentType);
}
我在代码中遗漏了什么?帮助将不胜感激。