Post方法在android中不起作用

时间:2013-08-01 20:38:10

标签: android http post httpresponse urlencode

所以我的代码在Java Project上运行正常,但它不能在android中运行。通过运行我的意思是它在我成功登录后没有跳转到帐户的页面。这是代码:

private void sendPost(String url, List<NameValuePair> postParams) 
        throws Exception {
 Log.i("SendPost",getCookies());
    HttpPost post = new HttpPost(url);
    post.setHeader("Host", "111.68.99.8");
    post.setHeader("Proxy-Connection", "keep-alive");
    post.setHeader("Cache-Control", "max-age=0");
    post.setHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    post.setHeader("Origin","http://111.68.99.8");
    post.setHeader("User-Agent", USER_AGENT);
    post.setHeader("Content-Type", "application/x-www-form-urlencoded");
    post.setHeader("Referer", "http://111.68.99.8/StudentProfile/");
    post.setHeader("Accept-Encoding","gzip,deflate,sdch");
    post.setHeader("Accept-Language", "en-GB,en-US;q=0.8,en;q=0.6");
    post.setHeader("Cookie", getCookies());
    post.setEntity(new UrlEncodedFormEntity(postParams,"UTF-8"));
    HttpResponse response = client.execute(post);
    int responseCode = response.getStatusLine().getStatusCode();
    BufferedReader rd = new BufferedReader(
                new InputStreamReader(response.getEntity().getContent()));
    StringBuffer result = new StringBuffer();
    String line = "";
    while ((line = rd.readLine()) != null) {
        Log.i("Line",line);
        result.append(line);
    }
      }
     

我很简单,我从pagecontent中获取postParams的值。一切都很好。我也从初始页面内容中获取了cookie。因此,一旦我获得了cookie,我就会在sendPost方法中再次使用相同的Cookie。标题的顺序也与浏览器发送的post方法相同。任何想法为什么它不在Android上工作但在Java项目中工作?

0 个答案:

没有答案