Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set charset in xml data in volley android

I got problem with data server get a xml data with this: "?xml version="1.0" encoding="UTF-8" standalone="yes"?" and string can't show me special chars ( paź ), how can i fix it? I tried to change the encoding on UTF-8 and UTF-16 but didn't work or my way was bad. Any idea?

public boolean loadDataFromRest( Context context){
    String szUrl = "http://host";
    alertDialogBuilder = new AlertDialog.Builder( context );

    StringRequest stringRequest = new StringRequest( Request.Method.GET, szUrl,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String szResponse) {
                            Log.d("DEBUG ", szResponse);
                }
like image 897
Muzzik Avatar asked Jan 28 '26 17:01

Muzzik


1 Answers

You can try following code to debug your response. I am getting all the body contents in response.data but not in StringResponse that uses parseCharset()

                @Override
                protected Response<String> parseNetworkResponse(NetworkResponse response) {
                    String StringResponse = "";
                    try {
                        StringResponse = new String(response.data,
                                HttpHeaderParser.parseCharset(response.headers));
                        HttpHeaderParser.parseCharset(response.headers);
                        Log.d(TAG, "--> Response Headers " + response.headers);
                        Log.d(TAG, "--> String Status Code " + response.statusCode);
                        Log.d(TAG, "--> String response data :  " + new String(response.data));
                        System.out.println("--> string response is " + StringResponse);
                    } catch (UnsupportedEncodingException e) {
                        return Response.error(new ParseError(e));
                    }
                    return super.parseNetworkResponse(response);
                }
like image 117
binit92 Avatar answered Jan 31 '26 08:01

binit92



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!