Hi Sean,

Even weirder .... when I tried this morning your string-append solution - which I had left in place - worked immediately with no changes from last night. The only thing different is I had closed DrRacket before going to bed and reopened it this morning. Maybe something was wonky in DrRacket? It had been running about ~14 hours yesterday at the point I started having trouble and I fought with it a couple more hours before quitting? But AFAICR, I've never seen that before.

However, as you discovered also, passing the data as #:data doesn't work and now I'm interested in why. ISTM that the URI + #:data should be identical to the string-append with "?" and #:method #"GET".

Also, Google recommends using POST if the data is sensitive, but I can't get POST to work even from a pure HTML form in a browser.

So now I'm really curious as to what's going on.

Thanks for your help,
George


On 4/21/2015 3:39 AM, Sean Kanaley wrote:
Hi George,

I'm not sure then -- I am in Racket 6.1.1. Here is the source that worked for me:

#lang racket
(require net/http-client
         net/uri-codec)

(define (lookup address)
  (let [
        (form-data  (alist->form-urlencoded
                     (list (cons 'address address)
                           )))
        (response #f)
        (lat  #f)
        (long #f)
       ]
    (printf "Looking up ~s~n" address)
    (printf "=> ~s~n" form-data)
    (with-handlers [
                    (exn:fail?
                     (lambda (e)
3; (fprintf (ferr) "~n~n%%~n~a~n%%~n" (format "Error: ~a" (exn-message e)))
                       ))
                   ]
      (let-values [
                   ((errcode header port)
(http-sendrecv "maps.googleapis.com <http://maps.googleapis.com>" (string-append "http://maps.googleapis.com/maps/api/geocode/json?"; form-data)
                                   ;#:ssl? ssl?
                                   ;#:port port
                                   #:version #"1.1"
                                   #:method  #"GET"
#:headers (list "Content-Type: application/x-www-form-urlencoded")
                                   ;#:data form-data
                                   ;#:content-decode decodes
                                   ))
                  ]
        (set! response (port->string port))
        ;(set! response (read-json port))
        (printf "=> ~s~n" response)
        ))
    ;(fprintf (ferr) "lat:~s long:~s~n"  lat long )
    (values lat long)
    ))

----------------------------------------------------------------------------

(I commented out the fprintfs to avoid dealing with ferr.)

It won't work if #:data is uncommented. I hope that helps, otherwise I'm stuck too.


--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to