问题
I'm writing my first Windows CE app using the .NET Compact Framework v3.5.
I need the app to be able to do an HTTP POST to a URL.
It appears that the .NET CF does not have System.Web.
So, I could use some guidence on how to accomplish and HTTP Posts using the .Net CF.
Thanks,
Greg
回答1:
Does this satisfy your needs?
You need to import
System.IO
System.Net
System.Net.HttpWebRequest
Try
Dim Request As HttpWebRequest = CType(WebRequest.Create("<The server>"), HttpWebRequest)
Request.AllowWriteStreamBuffering = True
Request.KeepAlive = False
Request.Credentials = CredentialCache.DefaultCredentials
Request.ContentType = "text/html"
Request.Method = "POST"
'If required
'Dim proxyURI As New Uri("193.129.241.46", UriKind.Absolute)
'Dim webProxy As New WebProxy
'webProxy.Address = proxyURI
'webProxy.Credentials = New NetworkCredential("", "")
'Request.Proxy = webProxy
Dim requestStream As Stream = Request.GetRequestStream
Dim Writer As New IO.BinaryWriter(requestStream)
Writer.Close()
Dim Reader As New BinaryReader(Request.GetResponse.GetResponseStream)
Reader.Close()
Catch ex As Exception
Throw ex
End Try
回答2:
The HTTPWebRequest class exists in the CF and can be used for posting and scraping the response. A quick search found several promising desktop articles on using them for doing POSTs, many of which can likely be ported.
来源:https://stackoverflow.com/questions/282545/net-compact-framework-3-5-http-post