我试图重建folloging非常简单的Post方法:
的https:/XYZ.com/v01/example.html
在Winforms客户端,它的工作方式如下:
WC = New Net.WebClient
Dim reqparm As New Specialized.NameValueCollection
reqparm.Add("DomainName", "XYZarco.com")
reqparm.Add("PIN", "1111")
Dim responsebytes() As Byte = WC.UploadValues(uri, "POST", reqparm) 'works
Dim responsebody As String = (New Text.UTF8Encoding).GetString(responsebytes) 'works
但是在Windows Phone 7.1上它不起作用,因为库不支持UploadValues。经过研究,我发现:
Dim U As String = "https://XYZ.com/v01/api.asp"
Dim uri As New Uri(U, UriKind.Absolute)
If WC Is Nothing Then
WC = New WebClient
'WC.Headers("HttpRequestHeader.ContentType") = " text/html"
WC.Headers("HttpRequestHeader.ContentType") = "application/x-www-form-urlencoded"
WC.Encoding = System.Text.Encoding.UTF8
End If
Dim Params As String = "DomainName=xyz.com&PIN=1111"
WC.Headers("HttpRequestHeader.ContentLength") = Params.Length.ToString
WC.UploadStringAsync(uri, "POST", Params)
但是没有发布数据。回应意味着:。 ERROR 01,DomainName不正确,请插入像Domain.com这样的Gold网站
有人能帮助我吗?
答案 0 :(得分:1)
WC.Headers("HttpRequestHeader.ContentType")
HttpRequestHeader是一个枚举。不带引号使用它:
WC.Headers(HttpRequestHeader.ContentType)