.Net Compact Framework 3.5 HTTP POST

◇◆丶佛笑我妖孽 提交于 2020-01-15 03:15:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!