S
S
Sergey Semenko2016-05-30 19:40:08
Android
Sergey Semenko, 2016-05-30 19:40:08

Android. Volley. java.io.IOException: unexpected end of stream on Connection. How to fix?

Please help me fix this error:

com.android.volley.NoConnectionError: java.io.IOException: unexpected end of stream on Connection{192.168.0.102:3000, [email protected] hostAddress=192.168.0.102 cipherSuite=none protocol=http/1.1} (recycle count=0)

Here is the code for sending the request:
private void loadMyInventory() {
        RequestQueue requestQueue = Volley.newRequestQueue(this);
        String url = "http://192.168.0.102:3000/api/loadMyInventory";
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
                new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                Toast.makeText(DepositeActivity.this, response.toString(), Toast.LENGTH_LONG).show();
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.d(TAG, "onErrorResponse: " + error.toString());
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                Map<String, String> headers = new HashMap<>();
                headers.put("Steam-Auth", getEncodedCredentials());
                return headers;
            }
        };
        requestQueue.add(request);
    }

This error occurs only when headers are added to the request. I tried to send a request not through the application - everything is fine.
PS Server on Node.js, maybe something needs to be fixed there?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Semenko, 2016-05-30
@abler98

It turned out pretty stupid: in the getEncodedCredentials method, the string was encoded in base64 and I mistakenly set the Base64.DEFAULT flag instead of Base64.NO_WRAP, so I got a line with hyphens.

private String getEncodedCredentials() {
        String result = Base64.encodeToString(credentials.toString().getBytes(), Base64.NO_WRAP);
        Log.d(TAG, "getEncodedCredentials: " + result);
        return result;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question