0

I'm trying to use the Qrickt API:
https://qrickit.com/qrickit_apps/qrickit_api.php

to create a QRCode for Google Map address in VBA. To do this I have to send a Http request like this:

"http://qrickit.com/api/qr.php?d=http://google.com/maps?q=Via+Roma,+1+Milano&qrsize=150&t=p&e=m"

The API documentation says:

*For non-English and special characters, url encode your data first.

The problem is that I cannot manage to pass an encoded address to the API. If I pass a string such as "Via+Roma", or "Via%20Roma", the generated QRCode URL is always

http://maps.google.com/maps?q=Via Roma, 1 Milano

so the QRCode image is created, but phone do not open directly google maps.

Can somehome help me?

Here's the code:

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
Teamothy
  • 2,000
  • 3
  • 16
  • 26
Marco
  • 5
  • 1
  • 4

2 Answers2

1

Their API accepts GET requests, and you're sending a POST.

Try:

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
Tim Williams
  • 154,628
  • 8
  • 97
  • 125
  • Hi Tim, thanks for your answer, I've tried with GET but the result is the same. My application is an Ms Access application, not Excel – Marco Feb 08 '19 at 07:34
1

I would add that you might consider using the function EncodeURL for encoding.

Application.EncodeURL("url")
QHarr
  • 83,427
  • 12
  • 54
  • 101
  • Hi QHarr, thanks for your answer. My application is an Ms Access application, not Excel :-( – Marco Feb 08 '19 at 07:36
  • So does that mean you don’t have access to that function? – QHarr Feb 08 '19 at 08:42
  • I assumed it was independent of excel as I am using application.function. You can always add an excel object library reference to access. – QHarr Feb 08 '19 at 08:43