views:

36

answers:

1

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"&gt;
<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!

+1  A: 

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.

Wrikken
@wrikken: thank you so much for your help. can you please show me an example
i am a girl
Quote 'Wrikken': _"Google has a multitude of VBA url encode examples."_
Wrikken
@wrikken: thank you. im getting THE URL does not use a recognized protocol" - what does this mean?
i am a girl
Wrikken
@wrikken: thank you again. now im getting something crazy like this "http://api.local.yahoo.com/MapsService/V1/geocode?appid=user123%26street%3D4511%20horizon%20hill%20ste%2E%20150%26city%3Dsan%20antonio%26state%3DTX%26zip%3D78229"
i am a girl
i am a girl
Wrikken