1

我从 HTTPPOST 得到响应,从中获取一个 URL 子字符串,然后对其执行 HTTPGET,但我无法得到任何响应。关于问题可能是什么的任何意见?

 String pkmspogout1 = result.substring(result.indexOf(",")+1,result.length());
                        Log.i("Lpkmspogout1 ", pkmspogout1);


                    HttpClient httpclient4 = new DefaultHttpClient();

                    HttpResponse logoutresponse  ;
                    try {
                        HttpGet httpget = new HttpGet(pkmspogout1);

                        logoutresponse = httpclient4.execute(httpget);
                        BufferedReader in2 = new BufferedReader(new InputStreamReader(logoutresponse.getEntity().getContent()));

                        StringBuffer sb2 = new StringBuffer("");

                        String line2 = "";
                        String NL2 = System.getProperty("line.separator");
                         while ((line2 = in2.readLine()) != null) {
                            sb2.append(line + NL2);

                        }
                        in2.close();


                        String pkmslogout5 = sb2.toString();
                        Log.i("logoutresponse from pkms", pkmslogout5+"");
                    } catch (Exception e) {}
4

2 回答 2

3

pkmspogout1正确的网址吗?此外,您应该确保执行以下操作以查看任何错误:

catch (Exception e) {e.printStackTrace();}

尝试按如下方式对 url 进行编码:

String[] url = pkmspogout1.split("com"); //Or whatever is the last part of the main url. 
                         //The letter "." means any character btw as it is a regular expression.
String finalUrl = url[0];
for(int i=0; i<url.length; i++){
     finalUrl += URLEncoder.encode(url[i],"UTF-8");
}

老实说有点粗糙......为什么在服务器端形成时最好编码它。

你可以试试:

pkmspogout1 = pkmspogout1.replace("http://","");
pkmspogout1 = URLEncoder.encode(pkmspogout1);
pkmspogout1 = "http://"+pkmspogout1;

看看是否只有“http://”破坏了您的网址。我仍然认为问题在于 url,因为您告诉我硬编码它工作正常。

于 2013-09-30T19:11:47.947 回答
0

它终于可以工作了,唷!我试过了 (pkmspogout1.trim()) 并且成功了!(URL 前后的空格是问题)。

于 2013-10-01T14:00:11.493 回答