【问题标题】:HttpURLConnection ResponseCode return 500HttpURLConnection ResponseCode 返回 500
【发布时间】:2015-03-19 02:48:41
【问题描述】:

我正在尝试通过 REST API 上传图像。当我尝试使用 HttpURL 连接时,它会返回 500 个响应代码。我还尝试通过多种方式解决问题,但不要找出问题。我的代码

        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 ="http://www.cashsheet.com/api/upload" 。

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

【问题讨论】:

    标签: java android rest upload image-uploading


    【解决方案1】:

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

    【讨论】:

    • Hello@Bruno 可能你说的对。但是 iSO 正确上传图片。我尝试通过 Android 上传。如果是服务器错误,然后 iOS 无法上传图片。
    猜你喜欢
    • 2023-04-07
    • 2018-12-12
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    • 2016-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多