2012-05-29 289 views
1

由于在我的项目中出现此问题,我遇到了一个障碍,任何帮助都将得到高度赞赏。通过ASP.net发送HTTP发布请求

我的问题是,我希望用户输入(他们的)目的地&电子邮件在我的网站。然后,我会将这些值填入以下网站的文本字段中,然后单击“请求测量按钮”。简而言之,一个简单的HTTP Post请求。

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

我的C#代码如下:

// 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)

回答

2

似乎url必须

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

因为是表单的动作。

+0

真棒它工作谢谢:) – asad