How to receive a http web request on a windows form application
How can one pass http get or post methods to a windows application? I require a webserver to send a get method to my windows form application that will query a database then reply back to a webserver
I'm developing a windows based search engine that searches a MySQL database. It receives a keyword from an SMS gateway software as a HTTP get request and should reply to the gateway software using the same HTTP request.This is my code. It is correctly searching the database but I don't know how to receive the get methods on the application however it's sending the messages to SMS gateway.
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"开发者_如何学JAVA _
& "&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
sounds like you want to host a webserver in your winforms application...you can use HttpListener
- see http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx
IF your application is not running as Administrator you will need to register the URL you are listerning to with netsh
though
精彩评论