我正在 java 中使用 apache HTTP 客户端发出 PUT 请求,但出现一些错误。这是我的功能:
public static void putRequest(String url, JSONObject setObject)
{
try
{
PutMethod put = new PutMethod(url);
HttpMethodParams httpParams = new HttpMethodParams();
if( setObject != null)
httpParams.setParameter("JSONString", setObject.toJSONString());
put.setParams(httpParams);
try
{
int result = httpclient.executeMethod(put);
System.out.println("HTTP response code : " + result);
String getResp = put.getResponseBodyAsString();
System.out.println("postresp ==> " + getResp);
put.releaseConnection();
}
catch(Exception e)
{
e.printStackTrace();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
我得到的回复是:
{"code":6,"message":"Internal Error"}
我哪里做错了?
最佳答案
这似乎是来自服务器的响应。 (我猜实际输出是 postresp ==> {"code":6,"message":"Internal Error"}
)
这不是代码中的错误,而是服务器端的内部错误。您应该检查服务器代码/日志/联系管理员。
关于java - HTTP 客户端 PUT 请求错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21301475/