1

当我调用下面的函数时,它会按预期写入一次(函数的最后一行)。

但是在被发布到的网站的 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
4

1 回答 1

1

事实证明,JSON 有效负载中缺少一个逗号。一旦我修复它工作正常。

我的新问题是:为什么这会产生一个双重职位,而不是一个失败的单一职位?!

于 2013-07-31T14:58:55.960 回答