vba - vba 中的 MSXML2.XMLHTTP60 对象不起作用
问题描述
我编写了一个程序来获取令牌以与 Microsoft Access 中的 PayPal API 一起使用。
但是 xmlhttp.send "grant_type = client_credentials") 行无法正常工作。有时我会收到两种类型的错误消息,有时它可以正常工作。
请帮我解决这个程序,哦,告诉我这个错误的原因!
Dim xmlhttp As New MSXML2.XMLHTTP60
Dim tempStr As String
Dim requestUrl_2 As String
Dim requestMethod As String
Dim encodeData As String
requestUrl_2 = "https://api.sandbox.paypal.com/v1/oauth2/token"
requestMethod = "POST"
encodeData = Base64EncodeString(ClientID & ":" & ClientSecret)
xmlhttp.Open requestMethod, requestUrl_2, False
xmlhttp.setRequestHeader "Accept", "application/json"
xmlhttp.setRequestHeader "Accept-Language", "en_US"
xmlhttp.setRequestHeader "Authorization", "Basic " & encodeData
xmlhttp.send "grant_type=client_credentials"
' ------------------------------------------------------------------------------------------------------
If xmlhttp.status = 200 Then
tempStr = Split(Split(xmlhttp.responseText, "access_token")(1), "token_type")(0)
tempStr = Left(tempStr, Len(tempStr) - 3)
tempStr = Right(tempStr, Len(tempStr) - 3)
MsgBox tempStr
Else
MsgBox "Error! Response status returned " & xmlhttp.status
End If
Set xmlhttp = Nothing
当我第一次运行应用程序并调用此过程时,我在 xmlhttp.send "grant_type = client_credentials") 行收到错误):“指定资源的下载失败。”
之后,我将错误行的代码更改为“xmlhttp.send”,然后出现错误。xmlhttp.responseText: {"error": "unsupported_grant_type", "error_description": "Grant Type is NULL"}
之后,我再次使用 xmlhttp.send "grant_type = client_credentials") 行运行该过程 - 并且没有更多错误。我可以无休止地使用这个程序(在我重新启动我的应用程序之前)
解决方案
推荐阅读
- c - 尝试使用 pdcurses 扩展库时出现与 gdi32 相关的错误
- c++ - 如何格式化推力::copy(ostream_iterator)
- python - 是否有 .endswith 可以在 (".html?") 之后打开后缀变体的文件(例如通过 ".html?p=1209401"、".html?p=92030" 等)
- python - openpyxl问题:单元格值被删除而不是移动
- python - 如何从两个列表创建字典,同时保持日子在一起?
- c# - web api函数抛出System.InvalidOperationException异常
- python - 清理地址数据 - 替换“St.” 带有“街道”和“圣”。与'圣'...如何区分?
- php - 在 PHP 中收集多个复选框的值(2 以相同的形式提交?)
- c++ - 转换为相同基础类型时的特征行为
- mysql - 父子链查询