当我调用下面的函数时,它响应按预期写入一次(函数的最后一行)。
但是在发布到的网站的api记录器上,它显示了两个帖子。不仅如此,但第一篇文章缺少认证标题。
有人会善意地查看这些代码并告诉我,我是否做了什么蠢事?
private function PostToWebsite(data, url)
Dim httpRequest, postResponse
Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP")
httpRequest.Open "POST", url, False, "un", "pw"
httpRequest.SetRequestHeader "Content-Type", "application/json"
httpRequest.setRequestHeader "Content-Length", len(data)
httpRequest.Send data
if httpRequest.status = 201 then
PostToWebsite = "ok/" & httpRequest.getResponseHeader("Location")
elseif httpRequest.status = 400 then
PostToWebsite= "error/Http 400 error: " & httpRequest.responseText
elseif httpRequest.status = 401 then
PostToWebsite= "error/Http 401 error: " & httpRequest.responseText
else
PostToWebsite= "error/Unknown status in PostToWebsite"
end if
Set httpRequest = nothing
RESPONSE.WRITE PostToWebsite 'this line writes only once
end function
答案 0 :(得分:1)
事实证明,JSON有效负载中缺少逗号。一旦我修复它工作正常。
我的新问题是:为什么会产生一个双重帖子,而不是一个失败的单一帖子?!