2012-06-19 115 views
2

我很擅長C#,但是我還沒有用過ASP.NET。我想將一個參數傳遞給一個頁面,頁面將把它打印給用戶。我做我的應用程序下面的傳遞型POST將參數傳遞給頁面

WebRequest request = WebRequest.Create("http://www.website.com/page.aspx"); 
request.Method = "POST"; 
string post_data = "id=123&base=data"; 
byte[] array = Encoding.UTF8.GetBytes(post_data); 
request.ContentType = "application/x-www-form-urlencoded"; 
request.ContentLength = array.Length; 

的參數,現在,我已經通過了我如何從我的頁面訪問它們的參數? 另外,我的上述方法是正確的asp.net發佈?我試圖用PHP,並且工作正常。

回答

2

在代碼背後的aspx頁面上,只寫

string id = Request.Form["id"].ToString(); 

如果它發佈的數據,並

string id = Request.Querystring["id"].ToString(); 

如果數據是在URL

+0

非常感謝,它的工作。 –

1

要發佈數據:

var request = (HttpWebRequest) WebRequest.Create("http://www.website.com/page.aspx"); 
request.Method = "POST"; 
request.ContentType = "application/x-www-form-urlencoded"; 

var postData = Encoding.UTF8.GetBytes("id=123&base=data"); 
request.ContentLength = postData.Length; 

using (var requestStream = request.GetRequestStream()) 
{ 
    requestStream.Write(postData, 0, postData.Length); 
} 

要重新廣告在ASP.NET項目上發佈的數據:

var id = Int32.Parse(Request.Form["id"]); 
var data = Request.Form["base"];