通过Jersey Java代码从OAUth API获得400响应但是通过REST Client

时间:2017-04-24 07:40:44

标签: java rest spring-boot oauth-2.0 jersey

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);
}

我在代码中遗漏了什么?帮助将不胜感激。

0 个答案:

没有答案