WinHttpRequest "send" 正在处理 Office 2007 产品,但不是 2013

WinHttpRequest "send" is working on office 2007 products but not 2013

我已经编写了一些代码来从我们的服务器检索文本并将该文本写入 word 文档。

我们正在将我们的办公套件从 2007 升级到 2013,但是我在 Word 2013 中测试我以前工作的代码时遇到了问题。

我已将其缩小到 http.send 行,这似乎没有发送任何内容。当我 运行 2007 套件上的代码时,我稍等片刻,然后跳转到 http_OnResponseFinished() Sub,但在 2013 套件中,它不会进入该子。

URL 是正确的,看起来 same/returns 2007 年和 2013 年套件之间的数据相同。

  Public Sub Download(Url As String, Optional Async As Boolean = True)

    Debug.Print "About to download text from url '" & Url & "'."

    http.Open "GET", Url, True 'http must be opened before it can send the request

    http.SetRequestHeader "Content-type", "application/json"

    http.Send 'Sends the request

'    If Wait Then
'        http.WaitForResponse
'    End If
End Sub
Private Sub http_OnResponseFinished()

    Dim Response As String

    Response = http.ResponseText

    WriteTextToWord Response

    Finished = True

    Debug.Print "Completed downloading and inserting text, icons and links."

    If err <> 0 Then
        Call writeToLog(err.Description)
    End If
End Sub

我发现了问题。

我在代码中进一步使用代理服务器,由于某种原因导致 http 对象无法连接到服务器。

通过删除代理我解决了这个问题,因为这个程序的使用只是内部的我认为不使用代理就可以了。