[英]Issue calling Rest API using ClientResponse Jersey
Facing issue when I call rest service from "Advance Rest Client" chrome extension I am getting proper response, but when I call same API using "ClientResponse" Jersey it gives me error 500 internal server error.. 当我从“ Advance Rest Client” chrome扩展程序调用REST服务时遇到问题,但是我得到了正确的响应,但是当我使用“ ClientResponse” Jersey调用相同的API时,出现了错误500内部服务器错误。
Here is my API URL: http://www.saksfifthavenue.com/main/ProductDetail.jsp 这是我的API URL: http : //www.saksfifthavenue.com/main/ProductDetail.jsp
Request Data: 索取资料:
{"productCode":"0400087200629","sku_id":"1689949379651610","itemQuantity":"1","zipCode":"10010","radius":"10","bmForm":"get_stores_with_inventory"} {“ productCode”:“ 0400087200629”,“ sku_id”:“ 1689949379651610”,“ itemQuantity”:“ 1”,“ zipCode”:“ 10010”,“ radius”:“ 10”,“ bmForm”:“ get_stores_with_inventory”}
public class JerseyClientPost
{
public static void main(String[] args)
{
try
{
Client client = Client.create();
WebResource webResource = client
.resource("http://www.saksfifthavenue.com/main/ProductDetail.jsp");
String input = "{\"productCode\":\"0400087200629\",\"sku_id\":\"1689949379651610\",\"itemQuantity\":\"1\",\"zipCode\":\"10010\",\"radius\":\"10\",\"bmForm\":\"get_stores_with_inventory\"}";
Product product = new Product();
product.setProductCode("0400087200629");
product.setItemQuantity("1");
product.setRadius("10");
product.setSku_id("1689949379651610");
product.setZipCode("10010");
product.setBmForm("get_stores_with_inventory");
ClientResponse response = webResource.post(ClientResponse.class, product);
System.out.println("Output from Server .... \n");
String output = response.getEntity(String.class);
System.out.println(output);
} catch (Exception e)
{
e.printStackTrace();
}
}
}
Output from Server .... 服务器的输出....
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Draft//EN">
<HTML>
<HEAD>
<TITLE>Error 500--Internal Server Error</TITLE>
<META NAME="GENERATOR" CONTENT="WebLogic Server">
</HEAD>
<BODY bgcolor="white">
<FONT FACE=Helvetica><BR CLEAR=all>
<TABLE border=0 cellspacing=5><TR><TD><BR CLEAR=all>
<FONT FACE="Helvetica" COLOR="black" SIZE="3"><H2>Error 500--Internal Server Error</H2>
</FONT></TD></TR>
</TABLE>
<TABLE border=0 width=100% cellpadding=10><TR><TD VALIGN=top WIDTH=100% BGCOLOR=white><FONT FACE="Courier New"><pre>
java.lang.IllegalArgumentException: malformed query string
at com.bluemartini.http.QueryParams.parseQueryOrPost(QueryParams.java:916)
at com.bluemartini.http.QueryParams.parsePostData(QueryParams.java:844)
at com.bluemartini.http.QueryParams.parsePostData(QueryParams.java:823)
at com.bluemartini.http.QueryParams.parsePostData(QueryParams.java:806)
at com.bluemartini.http.QueryParams.<init>(QueryParams.java:436)
at com.bluemartini.html.StandardRequestHandler.createFormValues(StandardRequestHandler.java:461)
at com.bluemartini.html.StandardRequestHandler.init(StandardRequestHandler.java:244)
at com.bluemartini.html.HTMLFilter.doFilter(HTMLFilter.java:340)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3496)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
</pre></FONT></TD></TR>
</TABLE>
</BODY>
</HTML>
Maybe the server doesn't know you are sending JSON. 也许服务器不知道您正在发送JSON。
you could try something like : 您可以尝试类似:
ClientResponse response = webResource.accept("application/json")
.type("application/json").post(ClientResponse.class, product);
see second answer to this post How to submit data with Jersey client POST method 查看此帖子的第二个答案如何使用Jersey客户端POST方法提交数据
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.