且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将JSON对象作为POST请求发送

更新时间:2023-01-17 08:08:20

您可能已经知道,JSON结构确实会引起严重的麻烦.就您而言,如果要验证您的{test:6, test2: 7}.

As you probably already know, JSON structure can really produce serious headaches. In your case, I would say its all about the quotes, as you can see in here if you try to validate your {test:6, test2: 7}.

尝试以下代码.对我来说似乎很合理:

Try the following code. It looks plausible to me:

Sub Post()

Dim URL As String, JSONString As String, objHTTP as Object

    Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
    URL = "http://localhost:3000/test"
    objHTTP.Open "POST", URL, False
    objHTTP.setRequestHeader "Content-type", "application/x-www-form-      urlencoded"
    objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"

    JSONString = "{""test"": 6,""test2"":7}"

    objHTTP.Send JSONString

End Sub