0
votes

I am receiving this error code.

E/camera_classes.callHttpPostToSendFiles: exception message e java.io.IOException: Server returned non-OK status: 400 message: Bad Request error stream : com.android.okhttp.internal.http.HttpTransport$FixedLengthInputStream@42353798at camera_classes.postMultipartEntity.finish(postMultipartEntity.java:161) at camera_classes.callHttpPostToSendFiles.postData(callHttpPostToSendFiles.java:193) at camera_classes.callHttpPostToSendFiles$1.doInBackground(callHttpPostToSendFiles.java:109) at camera_classes.callHttpPostToSendFiles$1.doInBackground(callHttpPostToSendFiles.java:105) at android.os.AsyncTask$2.call(AsyncTask.java:288) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:841)

The error is happening at

public List<String> finish() throws IOException {
        List<String> response = new ArrayList<String>();

        writer.append(LINE_FEED).flush();
        writer.append("--" + boundary + "--").append(LINE_FEED);
        writer.close();

        // checks server's status code first
        int status = httpConn.getResponseCode();
        String server_message = httpConn.getResponseMessage();
        if (status == HttpURLConnection.HTTP_OK) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    httpConn.getInputStream()));
            String line = null;
            while ((line = reader.readLine()) != null) {
                response.add(line);
            }
            reader.close();
            httpConn.disconnect();
        } else {
            throw new IOException("Server returned non-OK status: " + status + " message: " + server_message + " error stream : " + httpConn.getErrorStream());
        }

1) I am interested in getting more information on the error code (400 Bad Request) listed here, so I can understand what is causing the "400 Bad request" error. Can anyone help. I have tried all the available public methods - httpConn.getResponseMessage(), httpConn.getResponseCode() and httpConn.getErrorStream().

2) What does com.android.okhttp.internal.http.HttpTransport$FixedLengthInputStream@42353798 mean? This is the output of httpConn.getErrorStream().

1

1 Answers

0
votes

I'm using an upload method for Google Cloud XML Api like below. About your second question, maybe it's related to use of method setFixedLengthStreamingMode from HttpUrlConnection, as I used in my function, where you have to put the length of file being uploaded:

URL url = new URL("www.urltoupload.com");

HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();

httpCon.setDoOutput(true);
httpCon.setRequestMethod("PUT");
httpCon.setRequestProperty("Content-Type", Utils.getMimeType(path));
httpCon.setRequestProperty("Connection", "Keep-Alive");
httpCon.setFixedLengthStreamingMode((int) dest.length());

final DataOutputStream out = new DataOutputStream(httpCon.getOutputStream());

float bytesTotal = fileBeingUploaded.length();

int bytesRead;
byte buf[] = new byte[8192];
BufferedInputStream bufInput = new BufferedInputStream(new FileInputStream(dest));

while ((bytesRead = bufInput.read(buf)) != -1) {
    out.write(buf, 0, bytesRead);
    out.flush();
}

out.close();