neeraj t
neeraj t

Reputation: 4764

getting 505 responce from server

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 ?

Upvotes: 3

Views: 8211

Answers (1)

sdabet
sdabet

Reputation: 18670

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();

Upvotes: 8

Related Questions