2010-04-10 68 views

回答

2

您可以使用WebClient類。您需要將Content-Type標頭設置爲application/x-www-form-urlencoded,然後使用UploadData方法。該documentation of that method包含一個簡單的例子,這基本上歸結爲:

Dim myWebClient As New WebClient() 
myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded") 

Dim responseArray = myWebClient.UploadData("http://...", "POST", Encoding.ASCII.GetBytes(postData)) 
Dim response = Encoding.ASCII.GetString(responseArray) 

Wikipedia page of HTTP POST包含的POST數據如何必須被編碼的信息:

每個鍵 - 值對由'分離&'字符,並且每個鍵都通過'='字符與其值相分離。鍵和值都通過用'+'字符替換空格,然後在所有其他字符上使用URL編碼來轉義。

所以,你postData變量可以填補這樣(假設你要發佈的字段稱爲用戶名和密碼):

Dim postData = String.Format("Username={0}&Password={1}", _ 
    HttpUtility.UrlEncode(username), _ 
    HttpUtility.UrlEncode(password)) 
相關問題