getting 505 responce from server

8.1k Views Asked by At

Hi in my android project i m calling a webservice and sending get parameter through query string parameter , now problem is that if query string parameter value contains any white space then i am getting 505 error

                    URL url = new URL(urlstring.trim());                        
                    urlConnection = (HttpURLConnection) url.openConnection();
                    int response = urlConnection.getResponseCode();

I have one doubt if i use URLEncode(urlstring.trim(),"UTF-8")do i need to change my webservice code also ?

1

There are 1 best solutions below

2
sdabet On BEST ANSWER

You should encode only the values of your params:

    String urlString = "http://test.com?param1=" + URLEncoder.encode(value1, "UTF-8") + "&param2=" + URLEncoder.encode(value2, "UTF-8") ;

    URL url = new URL(urlstring.trim());                        
    urlConnection = (HttpURLConnection) url.openConnection();
    int response = urlConnection.getResponseCode();