将JSON对象作为POST请求发送时出错[VB.NET]

时间:2018-05-16 10:03:00

标签: json vb.net post

我正在尝试从VB.NET app(3.5 Framework)发送JSON对象。

我正在使用此代码:

 Private Function sendSMS()
        Dim objHTTP As Object
        Dim json As String
        Dim result As String
        Dim URL As String

        json = fJSON()
        objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
        URL = "https://api.XXXXXXXXX.com/api/3.0/sms/send"
        objHTTP.Open("POST", URL, False)
        objHTTP.setRequestHeader("Content-type", "application/json")
        objHTTP.send(json)
        result = objHTTP.responseText
        objHTTP = Nothing    
    End Function

    Private Function fJSON() As String
        fJSON = "{"
        fJSON = fJSON & """api_key"":""XXXXXXXXXXXXXXXXXXX"","
        fJSON = fJSON & """concat"":1,"
        fJSON = fJSON & """fake"":1,"
        fJSON = fJSON & """messages"":["
        fJSON = fJSON & "{"
        fJSON = fJSON & """from"":""SHOP"","
        fJSON = fJSON & """to"":""3400000000"","
        fJSON = fJSON & """text"":""LOREM IPSUM"""
        fJSON = fJSON & "}]}"
    End Function

但我在行代码中收到此错误:

行代码:

objHTTP.setRequestHeader("Content-type", "application/json")

错误:

System.Runtime.InteropServices.COMException(0x80004005):错误没有特定

有什么问题?

1 个答案:

答案 0 :(得分:-1)

有时用户没有足够的权限来运行某些COM方法。在这里你的异常说" System.Runtime.InteropServices.COMException(0x80004005)"它基于System.Runtime.InteropServices.COMException。要对其进行排序,您是否会以管理员身份运行Visual Studio并检查该逻辑是否适用于您?