1
我有各種PHP文件的數據發佈到(像用戶登錄時的密碼)我如何發佈到這些PHP從VB .net(桌面應用程序是Windows窗體,這不是關於ASP.net的)發佈到vb.net網頁(贏取窗體,桌面,而不是ASP.net)
我有各種PHP文件的數據發佈到(像用戶登錄時的密碼)我如何發佈到這些PHP從VB .net(桌面應用程序是Windows窗體,這不是關於ASP.net的)發佈到vb.net網頁(贏取窗體,桌面,而不是ASP.net)
您可以使用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))