HttpURLConnection ResponseCode返回500

时间:2015-01-20 18:35:57

标签: java android rest upload image-uploading

我尝试通过REST API上传图像。当我尝试使用HttpURL连接时,它会返回500个响应代码。我也尝试通过多种方式解决问题,找不到问题。我的代码< / p>

        URL url = new URL(urlLink);
        connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setUseCaches(false);
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type","multipart/form-data;boundary=----------V2ymHFg03ehbqgZCaKO6jy");
        connection.setRequestProperty("DocumentId", ""+ AppConstant.DocumentId);
        connection.setRequestProperty("Host", "www.cashsheet.com");
        connection.setRequestProperty("Authorization", au);
        connection.setRequestProperty("UserId", "" + AppConstant.UserId);
        int responseCode = connection.getResponseCode();
        Log.w("responseCode", "are"+responseCode);
        try {
            InputStream inputStream = connection.getInputStream();
        } catch (IOException ioe) {
            connection.disconnect();
            Log.w("IOException", "are"+ioe.getMessage());
            // If HTTP response code '401' is returned then try to resume
            // the expired
            // session on the reporting server by obtaining a new HTTP URL
            // Connection.
            if (connection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
                //throw new ClusterException(
                //      "The access to the requested resource was denied; the request may have been made without authorization credentials.");
            }
            // If response code other than '401' is returned then propagate
            // the IOException to the next level.
            else {
                //throw new ClusterException(ioe.getMessage());
            }
        }

它一直重新运行响应代码500并在urlLink上显示错误; urlLink =&#34; http://www.cashsheet.com/api/upload" 。 enter image description here

我无法捕捉到我的错误:(。请帮助我如何解决这个问题。谢谢。

1 个答案:

答案 0 :(得分:1)

HTTP 500是服务器端错误。我建议您联系谁保持此服务报告此错误。

相关问题