从服务器获得505响应

时间:2012-11-06 14:12:36

标签: java android apache http-status-code-505

嗨,在我的android项目中我调用webservice并通过查询字符串参数发送get参数,现在问题是如果查询字符串参数值包含任何空格,那么我得到505错误

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

我怀疑是否使用URLEncode(urlstring.trim(),"UTF-8")我是否还需要更改我的网络服务代码?

1 个答案:

答案 0 :(得分:7)

您应该只编码参数的值:

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