0

我试图重建以下非常简单的 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,域名不正确,请插入像Domain.com这样的黄金网站

有人可以帮我吗?

4

1 回答 1

1
WC.Headers("HttpRequestHeader.ContentType")

HttpRequestHeader 是一个枚举。不带引号使用它:

WC.Headers(HttpRequestHeader.ContentType)
于 2013-07-30T16:15:11.390 回答