nee*_*j t 3 java apache android http-status-code-505
嗨,在我的android项目中我调用webservice并通过查询字符串参数发送get参数,现在问题是如果查询字符串参数值包含任何空格,那么我得到505错误
URL url = new URL(urlstring.trim());
urlConnection = (HttpURLConnection) url.openConnection();
int response = urlConnection.getResponseCode();
Run Code Online (Sandbox Code Playgroud)
我有一个疑问,如果我使用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();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7631 次 |
| 最近记录: |