0

我有一个用python编写的代码,它以这种方式发送视图状态和表单值

发送('_ VIEWSTATE=%2FwEPDwULLTE0MDM4Mz.........%2BhFiTeLDMyk...................& _EVENTVALIDATION=%2FwEWA....I%2 .................mtK6HmOBny%2............NHcX5PO4r9oSpA&TextBox1='+payload+'&Button1=click\r\n')

点代表字符串的其余部分。现在我想通过 android 的 httppost 发送这个。我无法理解如何将上述代码转换为 httppost,我尝试将__VIEWSTATE,__EVENTVALIDATION作为键和字符串作为值,但这不起作用。怎么寄??我如何通过 httppost 发送上述字符串。

4

1 回答 1

0

这样做

private static final String DATA = "_VIEWSTATE=%2FwEPDwULLTE0MDM4Mz.........";  

public String send() {
    String result = null;
    try {
        HttpPost request = new HttpPost(new URI("<your POST uri>"));
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("data", DATA));
        request.setEntity(new UrlEncodedFormEntity(params));

        HttpClient client = new DefaultHttpClient(); 
        HttpResponse response = client.execute(request);
        BasicResponseHandler handler = new BasicResponseHandler();
        result = handler.handleResponse(response);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}

从后台线程调用 send() 方法。

于 2013-04-01T05:15:19.440 回答