当我调用下面的函数时,它会按预期写入一次(函数的最后一行)。
但是在被发布到的网站的 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