apache - 将 json 字符串作为 post 请求发送时的错误字符串参数

标签 apache vba excel tomcat winhttp

我在 excel 的 VBA 中为我的宏使用了这段代码:

Sub Macro1()

Dim URL As String, JSONString As String, objHTTP As Object
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
URL = "xxxxx"
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 = "{""name"": ""long"",""startDate"": 12345,""endDate"": 67890,""status"": ""in progress""}"
objHTTP.send JSONString
Debug.Print objHTTP.Status
Debug.Print objHTTP.responseText

End Sub

在即时窗口中,我收到此错误:

400 Apache Tomcat/8.0.28 - Error reportH1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}

HTTP Status 400 - Required String parameter 'name' is not present

type Status report

message Required String parameter 'name' is not present

description The request sent by the client was syntactica lly incorrect.

Apache Tomcat/8.0.28

我不知道怎么解决,请帮帮我!

最佳答案

I solved this problem:

Sub Macro1()
Dim URL As String, JSONString As String, objHTTP As Object
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
URL = "xxxxx?name=long&startDate=12345&endDate=67890&status=in progress"
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)"

objHTTP.send
Debug.Print objHTTP.Status
Debug.Print objHTTP.responseText
End Sub

关于apache - 将 json 字符串作为 post 请求发送时的错误字符串参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34037475/

相关文章:

excel - VLookup 抛出错误

php - 使用 777 写入文件夹

Apache tomcat部署

vba - excel vba-提取2个字符之间的文本

vba - Excel VBA : How to autocreate hyperlink from cell value?

excel - 使用间接引用另一张工作表上的 Excel 命名范围

apache - 用于 Apache 2.4.2 HTTP 服务器的 SVN 模块

wordpress - 我应该在 WordPress 中使用选项 - 索引吗?

vba - 使用 Excel VBA 填写并提交 Google 文档表单

当使用公式生成超链接时,VBA 打开 Excel 超链接不起作用