我试图从Excel中的VBA应用程序发送JSON对象。下面的代码正确地发送请求,但我无法弄清楚如何使用正文中的JSON对象发出请求。
Sub Post()
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)"
objHTTP.send ("test=6")
End Sub
如果我尝试发送" {test:6,test2:7}"并在服务器上记录请求的正文{' {parts:6,test:7}':'' }
答案 0 :(得分:3)
正如您可能已经知道的那样,JSON结构确实会产生严重的问题。在您的情况下,如果您尝试验证{test:6, test2: 7}
,我可以在here中看到所有关于引号的内容。
尝试以下代码。这对我来说似乎有道理:
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
答案 1 :(得分:0)
如果其他人在POSTS上为此而苦苦挣扎,则根本没有发送您的身体,特别是在objHTTP.Send行中使用变量而不是原义文本时,这对于我来说很有效小时,尽管我将变量声明为字符串:
const PREV_ICON = <span aria-hidden="true" className="carousel-control-prev-icon" />;
const NEXT_ICON = <span aria-hidden="true" className="carousel-control-next-icon" />;
const YourComponent = () => {
const [control, setControl] = useState({ prev: null, next: null });
....
useEffect( ... ,[sessionUserInfo.jigsawId, NEXT_ICON]); // whether you have NEXT_ICON here, or not, now makes no difference.
这对我不起作用,正如我在其他地方看到的那样
objHTTP.Send CStr(YourVariable)