0
如何將http get或post方法傳遞給Windows應用程序?我需要一個Web服務器發送get方法到我的Windows窗體應用程序,將查詢數據庫,然後回覆到網絡服務器如何在Windows窗體應用程序上接收http網頁請求
我正在開發一個基於Windows的搜索引擎,搜索MySQL數據庫。它從SMS網關軟件收到一個關鍵字作爲HTTP獲取請求,並且應該使用相同的HTTP請求回覆網關軟件。這是我的代碼。它正確地搜索數據庫,但我不知道如何在應用程序上接收get方法,但它將消息發送到SMS網關。
Private Sub bSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bSend.Click
Dim request As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim url As String
Dim username As String = "admin"
Dim password As String = "abc123"
Dim host As String = "http://127.0.0.1:9501"
Dim originator As String = "0724116972"
Try
url = host + "/api?action=sendmessage&" _
& "username=" & HttpUtility.UrlEncode(username) _
& "&password=" + HttpUtility.UrlEncode(password) _
& "&recipient=" + HttpUtility.UrlEncode(tbReceiver.Text) _
& "&messagetype=SMS:TEXT" _
& "&messagedata=" + HttpUtility.UrlEncode(tbMessage.Text) _
& "&originator=" + HttpUtility.UrlEncode(originator) _
& "&serviceprovider=" _
& "&responseformat=html"
request = DirectCast(WebRequest.Create(url), HttpWebRequest)
response = DirectCast(request.GetResponse(), HttpWebResponse)
MessageBox.Show("Response: " & response.StatusDescription)
Catch ex As Exception
MessageBox.Show("Error. Server Not running")
Me.Close()
End Try
End Sub
End Class
你到底在做什麼?是的,您可以編寫響應Web請求的應用程序。你基本上正在編寫一個Web服務器。那麼你有另一個Web服務器會發出請求? Web服務器通常會響應請求,而不是發出請求。真的不清楚你想要完成什麼或爲什麼。 – David
http://stackoverflow.com/questions/2615335/post-to-webpage-in-vb-net-win-forms-desktop-not-asp-net –
請檢查下面的例子 – Staypa