发送HTTP POST请求通过ASP.net [英] Send HTTP Post Request through ASP.net

查看:119
本文介绍了发送HTTP POST请求通过ASP.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经打了一个路障,由于在我的项目这个问题,任何形式的帮助将是非常美联社preciated。

I've hit a road block due to this problem in my project, Any kind of help will be highly appreciated.

我的问题是,我想用户输入(他们的)目的地&安培;电子邮件在我的网站。然后,我会采取这些值,并在以下网站在文本字段填写,然后点击要求测量按钮。总之一个简单的HTTP POST请求。

My problem is that I want users to enter (their) destination & email at my website. Then I'll take those values and fill in the text fields at the following website and then click the "request measurement button". In short a simple HTTP Post request.

http://revtr.cs.washington.edu/

我的C#code是如下:

My C# code is as follows:

    // variables to store parameter values
    string url = "http://revtr.cs.washington.edu/";

    // creates the post data for the POST request
    string postData = ("destination=www.thechive.com&node=161&email=abc%40xyz.edu.pk&prediction=If+you+believe+you+know+the+traceroute+%28for+instance%2C+if+you+are+trying+out+our+system+using+a+destination+that+you+actually+control%29%2C+please+cut-and-paste+the+traceroute+into+this+box+to+aid+us+in+improving+our+system.");

    // create the POST request
    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
    webRequest.Method = "POST";
    webRequest.ContentType = "application/x-www-form-urlencoded";
    webRequest.ContentLength = postData.Length;

    // POST the data
    using (StreamWriter requestWriter2 = new StreamWriter(webRequest.GetRequestStream()))
    {
        requestWriter2.Write(postData);
    }

    //  This actually does the request and gets the response back
    HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse();

    string responseData = string.Empty;

    using (StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream()))
    {
        // dumps the HTML from the response into a string variable
        responseData = responseReader.ReadToEnd();
    }

    //  Now, find the index of some word on the page that would be 
    //     displayed if the login was successful
    int index = responseData.IndexOf("Measuring");

    if (index > -1)
        ListBox1.Items.Add("SUCCESS");

但在 responseData 显示的按钮是在程序运行时没有被点击(我从VS2010的调试器这个信息)

But the responseData shows that the BUTTON hasn't been clicked when the program is run (I got this info from debugger of VS2010)

推荐答案

似乎URL必须是

string url = "http://revtr.cs.washington.edu/measure.php";

由于是窗体的作用。

since is the action of the form.

这篇关于发送HTTP POST请求通过ASP.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆