本帖最后由 jodelle 于 2012-12-23 20:10:03 编辑

解决方案 »

  1.   

    你这个可以不需要POST的吧?应该Get就行了。String body = "http://account.testsite.com/q_account.php?_act=login&type=username&email=" + URLEncoder.encode("testusername","utf-8") + 
    "&password=" + URLEncoder.encode("testpassword","utf-8");
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(body);
    httpGet.addHeader("User-Agent", "testAgent");
    httpGet.addHeader("Content-Type", "application/x-www-form-urlencoded");
    httpGet.addHeader("Accept-Charset", "GBK");
    HttpResponse httpResponse = httpClient.execute(httpGet);
    System.out.println("从服务器端获取的内容为:\n" + EntityUtils.toString(httpResponse.getEntity()));
      

  2.   

    谢谢,我准备做个客户端登陆网站的,Get方式可以登陆吗?
      

  3.   


    这个看目标系统的实现机制,如果是J2EE应用则一般没啥区别。用POST也很容易改。
       HttpGet httpGet = new HttpGet(body);
    修改为:
       HttpPost httpPost = new HttpPost(body);
    参数麻烦点:
    List<NameValuePair> nvps = new ArrayList <NameValuePair>();
    nvps.add(new BasicNameValuePair("type", "user")); // 一个一个来
    ......
    httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));