Hello, I am trying to use volley while using http client, but the server can only send EUC-KR, so while I was trying, the Korean alphabet kept breaking and I am uploading it like this.
volley is
BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), "EUC-KR"));
It's also because I'm not good at English that there's nothing I can read the stream itself like a phrase I tried the string that comes in Korean on the endcoder, but it didn't work, so I'm leaving it like this. Help me. Thank you for reading it.
volley java android
Volley encodes using charset of Response header coming down from the server. The relevant code can be found below.
First, check to see if the Content-Type of the Response header that the server drops.
Content-Type: application/json; charset=euc-kr
Of course, you can force conversion in code. Please refer to the code below and create a request object to match the current code. The key in the code below is String jsonString = newString(response.data, "euc-kr");
.
public class JsonEucKrRequest extends JsonRequest<JSONObject> {
public JsonEucKrRequest(int method, String url, JSONObject jsonRequest,
Listener<JSONObject> listener, ErrorListener errorListener) {
super(method, url, (jsonRequest == null) ? null : jsonRequest.toString(), listener,
errorListener);
}
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
try {
String jsonString = new String(response.data, "euc-kr");
return Response.success(new JSONObject(jsonString),
HttpHeaderParser.parseCacheHeaders(response));
} } catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} } catch (JSONException je) {
return Response.error(new ParseError(je));
}
}
}
Note
© 2024 OneMinuteCode. All rights reserved.