我正在尝试使用Qrickt API
https://qrickit.com/qrickit_apps/qrickit_api.php
在VBA中为Google Map地址创建QRCode。 为此,我必须发送这样的Http请求:
"http://qrickit.com/api/qr.php?d=http://google.com/maps?q=Via+Roma,+1+Milano&qrsize=150&t=p&e=m"
API文档说:
*对于非英语和特殊字符,请先使用url对数据进行编码。
问题是我无法设法将编码的地址传递给API。 如果我传递“ Via + Roma”或“ Via%20Roma”之类的字符串,则生成的QRCode URL始终为
http://maps.google.com/maps?q=Via Roma, 1 Milano
因此创建了QRCode图像,但电话无法直接打开Google地图。
有人可以帮我吗?
谢谢
代码在这里:
Public Function f_QRCode(ByVal Address As String, ByVal Destination As String) As Boolean
On Error GoTo Err_Handler
Const ApiPath As String = "https://qrickit.com/api/qr.php?d=http://maps.google.com/maps?q="
Dim WinHttpReq As Object '\\ Oggetto che serve al download del verbale
Dim fic As Integer
Dim buffer() As Byte
Dim URL As String
'\\ Costruisco l'URL
URL = ApiPath + "Via%20Roma%2C%%201%20Milano" + "&qrsize=150&t=p&e=m"
'\\ Creo l'oggetto per la connessione
Set WinHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
WinHttpReq.Open "POST", URL, False
WinHttpReq.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
WinHttpReq.send
If WinHttpReq.Status = 200 Then
fic = FreeFile
Open Destination For Binary Lock Read Write As #fic
buffer = WinHttpReq.responseBody
Put #fic, , buffer
Close #fic
f_QRCode = True
Else
MsgBox "Error"
End If
ExitHere:
Erase buffer
Set WinHttpReq = Nothing
Exit Function
Err_Handler:
Resume ExitHere
End Function
答案 0 :(得分:1)
他们的API接受GET请求,并且您正在发送POST。
尝试:
URL = ApiPath + "Via%20Roma%2C%%201%20Milano" + "&qrsize=150&t=p&e=m"
Set WinHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
WinHttpReq.Open "GET", URL, False
WinHttpReq.send
答案 1 :(得分:0)
我要补充一点,您可以考虑使用函数EncodeURL进行编码。
Application.EncodeURL("url")