1

这里首先要向 url 发出 http 请求,然后想将一些数据发布到 user.here 我正在使用的输入的 url 中JSOUP。任何人都可以提出一些简单的方法。对 Ktutorial 感到困难。按照这个任何人建议任何示例或简单的教程。提前致谢

在此处添加代码

String strResp = null;
            HttpClient client = new DefaultHttpClient();
            HttpPost post = new HttpPost(
                    "http://motinfo.direct.gov.uk/internet/jsp/ECHID-Internet-History-Request.jsp");

            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair(
                    "Vehicle registration mark from number plate", "DU06BFZ"));
            nameValuePairs
                    .add(new BasicNameValuePair(
                            " MOT test number from-VT20 test certificate-VT30 refusal certificate ",
                            "435294573022"));

            /*
             * nameValuePairs.add(new BasicNameValuePair("MOT test number",
             * "000000"));
             */

            try {
                loadingProgressBar = (ProgressBar) findViewById(R.id.progressBar1);
                loadingProgressBar.setVisibility(View.VISIBLE);
                post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = client.execute(post);
                strResp = EntityUtils.toString(response.getEntity());
                Document document = Jsoup.parse(strResp);
                Element link = document.select("a").first();
                String text = document.body().text();       
                } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return strResp;
        }
4

2 回答 2

0

使用AsyncHttpClient

AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();

params.put("username",username);
params.put("password",pass);

client.post("http://www.example.com/", params, new AsyncHttpResponseHandler() {
    @Override
        public void onSuccess(String response) {
            //parse data with Jsoup
        }
});
于 2013-09-10T11:09:36.347 回答
0

使用JSOUP您可以执行Post以下操作:

// need http protocol
  Document doc = Jsoup.connect("http://www.something.com") // your_url
  .data("key_one", "value_one")
  .data("key_two", "value_two")
  // and other hidden fields which are being passed in post request.
  //It’s recommended to specify a “userAgent” in Jsoup, to avoid HTTP 403 error messages.
  .userAgent("Mozilla")  
  .post();
   System.out.println(doc); // will print html source of page ,you are trying to connect.
于 2013-09-10T11:21:28.930 回答