1

如何通过POST DATA下面的访问登录验证并从httpFox获取登录网站。在其他时候,我尝试测试该GetRequestStreamCallback()操作是否会起作用,我发现该操作不起作用并且它以DoWork(). 为什么它不继续做GetRequestStreamCallback()操作。谢谢你帮助我。

发布数据

Parameter                         value
__EVENTTARGET
__EVENTARGUMENT
__VIEWSTATE                       /wEPDwUIMTQwOTY1MTgPZBYCAgMPZBYEAgEPZBYCZg9kFgICAQ9kFgJmD2QWAgINDxAPFgIeB0NoZWNrZWRoZGRkZAIFDzwrAAgCAA8WBB4PRGF0YVNvdXJjZUJvdW5kZx4OXyFVc2VWaWV3U3RhdGVnZAYPFgIeCklzU2F2ZWRBbGxnDxQrAAkUKwABFgIeDlJ1bnRpbWVDcmVhdGVkZxQrAAEWAh8EZxQrAAEWAh8EZxQrAAEWAh8EZxQrAAEWAh8EZxQrAAEWAh8EZxQrAAEWAh8EZxQrAAEWAh8EZxQrAAEWAh8EZ2QWAmYPZBYCAgEPZBYCZg9kFgJmD2QWAmYPZBYCZg9kFgICAg9kFgJmD2QWAmYPZBYCZg9kFgZmD2QWBmYPZBYCZg9kFgJmD2QWCAIBDw8WAh4ISW1hZ2VVcmwFG34vcHJvZHVjdGltYWdlL0NBRDAwNTQ3LmpwZ2RkAgMPDxYCHgRUZXh0BQhDQUQwMDU0N2RkAgUPDxYCHwYFVENBUkQgUFJFUFJJTlQgS0lOT0tVTklZQSBQVkMgSVNPIDAuNzZNTSA1QyAxQyAgRk9SIFBSRVBSSU5UIEtJTk9LVU5JWUEgQ0FSRCBERVNJR04gMmRkAgcPDxYCHwYFD1BSRVBSSU5URUQgQ0FSRGRkAgIPZBYCZg9kFgJmD2QWCAIBDw8WAh8FBRt+L3Byb2R1Y3RpbWFnZS9CQVIwMTE1NC5qcGdkZAIDDw8WAh8GBQhCQVIwMTE1NGRkAgUPDxYCHwYFLEdGUzQ0NzAgR1JZUEhPTiBHRlM0NDAwIEZJWEVEIFNDQU5ORVIgMkQgVVNCZGQCBw8PFgIfBgUHR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oginView1$Login1$UserName        USERNAME
LoginView1$Login1$Password        PASSWORD
LoginView1$Login1$LoginButton     Log In
ASPxDataView1                     0;3;3
DXScript                          1_141,1_79,1_123,1_82

下面的代码是我到目前为止的工作。

public void DoWork()
    {
        var url = "xxxxxxxx";
        // Create the web request object
        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
        webRequest.Method = "POST";
        webRequest.ContentType = "application/x-www-form-urlencoded";
        // Start the request
        webRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), webRequest);    
    }
void GetRequestStreamCallback(IAsyncResult asynchronousResult)
{
    HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
    // End the stream request operation
    Stream postStream = webRequest.EndGetRequestStream(asynchronousResult);
    // Create the post data
    // Demo POST data 
    string postData = 
    byte[] byteArray = Encoding.UTF8.GetBytes(postData);
    // Add the post data to the web request
    postStream.Write(byteArray, 0, byteArray.Length);
    postStream.Close();
    // Start the web request
    webRequest.BeginGetResponse(new AsyncCallback(GetResponseCallback), webRequest);
}

void GetResponseCallback(IAsyncResult asynchronousResult)
{
    try
    {
        HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
        HttpWebResponse response;
        // End the get response operation
        response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult);
        Stream streamResponse = response.GetResponseStream();
        StreamReader streamReader = new StreamReader(streamResponse);
        var Response = streamReader.ReadToEnd();
        streamResponse.Close();
        streamReader.Close();
        response.Close();
    }
    catch (WebException e)
    {
        // Error treatment
        // ...
    }
}

private void button1_Click(object sender, RoutedEventArgs e)
{
    DoWork();
}
4

0 回答 0