Alex Gordon
Alex Gordon

Reputation: 60751

what is the problem with my http GET?

in VBA i am creating a URL:

URL = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=" & yahoo & "&street=" & street & "&city=" & city & "&state=" & state & "&zip=" & zip

for example it sets itself to equal this:

http://api.local.yahoo.com/MapsService/V1/geocode?appid=username123&street=1893 n. clyde morris blvd &city=daytona beach&state=FL&zip=32117

when i manually go to this URL, IT WORKS FINE.

however when i do this:

'Create Http object
If IsEmpty(http) Then Set http = CreateObject("WinHttp.WinHttpRequest.5.1")

'Send request To URL
http.Open "GET", URL

http.send
'Get response data As a string

response = http.responseText

it's giving me this for the response:

response="Watch :   : response : "<!doctype html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>Yahoo! - 400 Bad Request</title><style>
/* nn4 hide */ 
/*/*/
bod........"

please note that 50% of the time it returns the correct URL and 50% it gives me a 400 bad request

what am i doing wrong?

wrikken has suggested that i get a URLencoder, but i believe that it was encoding it correctly!

Upvotes: 0

Views: 3953

Answers (1)

Wrikken
Wrikken

Reputation: 70490

You need to url-encode all your query parameters, otherwise they may result in invalid URLs, depending on their actual value (for instance, a space should be a + or a %20). Google has a multitude of VBA url encode examples, it appears there's no built-in function for it.

Upvotes: 1

Related Questions