您好,在我的 android 项目中,我正在调用 Web 服务并通过查询字符串参数发送获取参数,现在的问题是,如果查询字符串参数值包含任何空格,那么我将收到 505 错误
URL url = new URL(urlstring.trim());
urlConnection = (HttpURLConnection) url.openConnection();
int response = urlConnection.getResponseCode();
我有一个疑问,如果我使用 URLEncode(urlstring.trim(),"UTF-8")
我还需要更改我的网络服务代码吗?
最佳答案
您应该只对参数的值进行编码:
String urlString = "http://test.com?param1=" + URLEncoder.encode(value1, "UTF-8") + "¶m2=" + URLEncoder.encode(value2, "UTF-8") ;
URL url = new URL(urlstring.trim());
urlConnection = (HttpURLConnection) url.openConnection();
int response = urlConnection.getResponseCode();
关于java - 从服务器获取 505 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13252814/