使用Visual Studio 2013在VB中发布Jsondata会导致消息:“invalid parameter”

时间:2016-09-01 14:18:52

标签: json vb.net json.net msxml6

我使用有效的URL和有效的API密钥(用户名)调用PostJsontext。 发布jsontext会在行中生成“invalid parameter”消息:    。发送(Jsontext)

使用相同的例程:   .Open(“GET”,Xurlget,False,StrUsername,“”)   。发送() 产生有效的.responsetext。

不知道该去哪里或怎样做才能发布所有数据。 为什么该行会产生错误,如何解决?

Public Sub PostJsonText(ByVal xurl As String, ByVal Xurlget As String, ByVal StrUsername As String, ByVal StrPassword As String, ByRef xJsonText As String, ByRef OkAuthenticateCredentials As Boolean, ByRef Credstatus As Int32)

    Dim Jsonservice As Object = CreateObject("MSXML2.XMLHTTP.6.0")
    Dim Jsontext As String


    jsontext =
        "{""idvatgroup"":3996,""idsupplier"":111,""productcode"":""tester2"",""name"":""tester2"",""price"":22,""fixedstockprice"":22,""productcode_supplier"":""22""}"


    With Jsonservice
        .Open("POST", Xurlget, False, StrUsername, "")

        .setRequestHeader("Content-Type", "application/json")
        .setRequestHeader("Accept", "application/json")

       .setRequestHeader("Authorization", "Basic " & StrUsername)
       .send(jsontext)

        Credstatus = .Status
        If .Status <> 401 Then
            jsontext = .Responsetext
            OkAuthenticateCredentials = True
        Else
            OkAuthenticateCredentials = False
            JsonText = "Error: Invalid Credentials!"
        End If
    End With
    Jsonservice = Nothing

0 个答案:

没有答案