2012-05-29 213 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