简体   繁体   English

为什么我收到JSON请求时收到500错误?

[英]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.

相关问题 为什么在控制器中从邮递员请求中收到空值? - Why am I receiving null from postman request in my controller? 我正在尝试访问页面,但收到 500 错误 - I am trying to reach page and I am receiving 500 error 为什么会收到http 500响应? - Why am I getting a http 500 response? 为什么我在Jersey REST API上的POST收到500响应? - Why am I getting a 500 response for my POST on my Jersey REST API? 为什么我收到此sql错误? - Why I am receiving this sql error? 为什么我会收到堆栈溢出错误? - Why am I receiving a Stack overflow error? 为什么我收到“不支持请求方法 'POST'”? 我在邮递员上收到错误代码 405 - Why am I receiving a "Request method 'POST' not supported" ? I get error code 405 on postman thymeleaf 模板在 chrome 中发送请求时没有得到所有响应,我正在从数据库接收数据绑定是否有任何错误? - thymeleaf template not getting all response while sending request in chrome, I am receiving data from database is there any error in binding? 为什么我在代码中的线程“main”java.lang.StringIndexOutOfBoundsException 错误中收到异常? - Why am I receiving an Exception in thread "main" java.lang.StringIndexOutOfBoundsException error in my code? 为什么在我的Maven动态Web模块中收到此404错误? - Why am I receiving this 404 Error in my Maven Dynamic Web Module?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM