簡體   English   中英

為什么我收到JSON請求時收到500錯誤?

[英]Why am I receiving 500 error in response to my JSON request?

我正在嘗試將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);

錯誤

java.io.IOException: Server returned HTTP response code: 500 for URL: http://example.com/service?apiKey=12345

由於服務器或服務器應用程序在處理您的請求時發生內部錯誤。

該錯誤只能通過對Web服務器軟件的修復來解決。 這不是客戶端問題。 由Web服務器站點的操作員確定和分析日志,日志應提供有關該錯誤的更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM