如何通过Httppost发送Viewstate String,asp页面值

时间:2013-04-01 04:32:10

标签: android asp.net http-post

我有一个用python编写的代码,以这种方式在viewstate和formvalues中发送

发送('_ VIEWSTATE =%2FwEPDwULLTE0MDM4Mz .........%2BhFiTeLDMyk ...................&安培; _EVENTVALIDATION =%2FwEWA .... I%2 ................. mtK6HmOBny%2 ............ NHcX5PO4r9oSpA&安培; TextBox1中='+净荷+ '& Button1 =点击\ r \ n')

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

1 个答案:

答案 0 :(得分: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()方法。