httputils2 error message

drgottjr

Well-Known Member
Licensed User
i've run into a funny error from google when i use httpjob/httputils2 to request an image. let me say first off that i use httpjob/httputils2 all the time to request text and images, some of them from google. never had a problem.

this code:
dim gRequest as String
dim parms(6) as String
dim job as httpjob
,
job.Initialize( "SV", Me )
gRequest = "http://maps.googleapis.com/maps/api/streetview"
parms(0) = "size"
parms(1) = "300x200"
parms(2) = "location"
parms(3) = "40.720032,-73.988354"
parms(4) = "sensor"
parms(5) = "false"
job.Download2(gRequest, parms)
job.GetRequest.Timeout = 10000

gets this error from google:
<a href=//www.google.com/><img src=//www.google.com/images/errors/logo_sm.gif alt=Google></a>
<p><b>400.</b> <ins>That’s an error.</ins>
<p>Your client has issued a malformed or illegal request. <ins>That’s all we know.</ins>

so, apparently, i've a malformed request or an illegal one. that's all they know... of course, they may know more, and the actual error (if any) may or may not have anything to do with a malformed or illegal request. all i can do is go with what they tell me.

as you can see from my code above, the request, when built by my app will be:
http://maps.googleapis.com/maps/api...00&location=40.720032,-73.988354&sensor=false


i know the "," separating the latitude and longitude will be changed to %2C, but other than that, the job.download2() call in httpjob an httputils2service modules should handle everything else normally. just as it always does. to make sure, i added a log line to httpjob module to see what it is sending. the log shows:
http://maps.googleapis.com/maps/api...00&location=40.720032,-73.988354&sensor=false

which is exactly what i am expecting it to send. so, nothing malformed there that i can pick up.

i copied that output line from the log to the clipboard and pasted it into chrome and internet explorer on the desktop:
http://maps.googleapis.com/maps/api...00&location=40.720032,-73.988354&sensor=false
and both return the image from google that i am expecting. again, nothing malformed or illegal. on the surface.

i copy and paste that url into a little "wwwget" shell script on my linux host and the headers returned from google show a code 200.
$ cat forme
HTTP/1.0 200 OK
Content-Type: image/jpeg
Date: Sun, 30 Dec 2012 23:49:27 GMT
Expires: Mon, 31 Dec 2012 23:49:27 GMT
Access-Control-Allow-Origin: *
Server: staticmap
Content-Length: 15526
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Cache-Control: public, max-age=86400
Age: 35

at this point i can only assume that httpjob is sending something other than what i see in the log. that's a little simplistic, since it all has to filter back to the underlying java; i don't mean to imply there's something wrong with httpjob or httputil2service.

i took the url and modfied it and directed it to my own server to see what the differences, if any, might be between a browser and the app

when sent from a desktop browser:
GET /maps/api/streetview?size=300x200&location=40.720032%2C-73.988354&sensor=false HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Accept-Encoding: gzip, deflate
Host: Dr George E Ott, Jr Online
Connection: Keep-Alive

when set from the device:
GET /maps/api/streetview?size=300x200&location=40.720032%2C-73.988354&sensor=false HTTP/1.1
Host: Dr George E Ott, Jr Online
Connection: Keep-Alive

i note the Accept, Accept-Language, Accept-Encoding and User-Agent headers are missing when the device sends the request. i would assume these headers are always missing from a request sent by the device. now, i can successfully request a geocode and a map from google in the same app (but to a slightly different url), so let's say for argument's sake that this particular server used by google wants those headers. my question is: how can i send them? in another environment where i would have made my own
socket calls, i could put whatever headers i thought a server might be expecting. i'm not even sure this is where the problem is, but the only difference between a standard browser and the device seems to be the missing headers from the device. i'd like to start there. any thoughts? thanks in advance.

-go
 

drgottjr

Well-Known Member
Licensed User
sorry, missed that. let me see if that makes a difference. thanks


a brief follow-up if anyone is looking: adding the headers doesn't do it. but i just plug the whole url into webview.loadurl, and it works fine. all of a sudden my request is well formed and legal. not the way i wanted to go, but we take what we can get.
 
Upvote 0
Top