Answer the question
In order to leave comments, you need to log in
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)
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);
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question