[英]Why am I receiving 500 error in response to my JSON request?
I am trying to send the a JSON to server but it constantly returns 500 error. 我正在尝试将JSON发送到服务器,但它不断返回500错误。
java.lang.String contentToPost = jsarray.toJSONString();
java.net.URLConnection connection = new java.net.URL("http://example.com/service?apiKey=12345").openConnection();
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestProperty("Content-Length", "" + contentToPost.length());
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Cache-Control", "no-cache");
java.io.OutputStream stream = connection.getOutputStream();
stream.write(contentToPost.getBytes());
stream.close();
System.err.println("request is sent");
// Read the response
java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
java.lang.StringBuffer sb = new java.lang.StringBuffer();
java.lang.String str = br.readLine();
while (str != null) {
sb.append(str);
str = br.readLine();
}
br.close();
java.lang.String responseString = sb.toString();
System.err.println(responseString);
Error 错误
java.io.IOException: Server returned HTTP response code: 500 for URL: http://example.com/service?apiKey=12345
由于服务器或服务器应用程序在处理您的请求时发生内部错误。
This error can only be resolved by fixes to the Web server software. 该错误只能通过对Web服务器软件的修复来解决。 It is not a client-side problem.
这不是客户端问题。 It is up to the operators of the Web server site to locate and analyse the logs which should give further information about the error.
由Web服务器站点的操作员确定和分析日志,日志应提供有关该错误的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.