java - HttpURLConnection 响应代码返回 500

标签 java android rest upload image-uploading

我尝试通过 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”。 enter image description here

我无法发现我的错误是什么:(。请帮助我如何解决这个问题。谢谢大家。

最佳答案

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

关于java - HttpURLConnection 响应代码返回 500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28052728/

相关文章:

java - 如何在@AfterMethod 中获取TestNG/Selenium 的测试结果状态?

iphone - 向 iphone/android app/webapp 发送通知有哪些选项?

delphi - Indy 和 REST - 我可以防止异常吗?

java - 从不同的类调用 jdbc 连接获取 "java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver"

java - 如何编写使用 json 格式作为对象列表的 REST API 方法

java - 有没有办法打印出没有 'adding' 空格的文本?

android - 增加超时以摆脱 Cordova/PhoneGap 应用程序中的 "The server is taking longer than expected to respond"

android - 我可以在网页上发布需要帐户的应用程序吗?

rest - spring boot 中 Rest 资源的 NotImplementedException

rest - IllegalStateException:已提交;在 500 org.eclipse.jetty.io.EofException 之前提交