network.request not working on device but fine in simulator

I am using google’s Places API to retrieve a list of nearby places and display them in a list. It works fine in the simulator and does not work in the device (HTC Thunderbolt). It is like the listener never fires and the app will eventualy crash without displaying data.

...  
--listener for Places API request  
local function networkListener( event )  
  
 if ( event.isError ) then  
-- myText.text = "Network error!"  
 else   
-- myText.text = "See Corona Terminal for response"  
  
 --decode json table  
 local response = event.response  
 response = json.decode(response )  
 local status = response.status  
 print(status)   
 local rTest = display.newText(status, 0, 0, native.systemFontBold,22)  
  
 if status == "OK" then  
 local testValue = response.results[1].geometry.location.lat  
 local testValue2 = response.results[1].geometry.location.lng  
  
 Gdata= response.results  
 local i = 1  
 while Gdata[i] do  
 Gdata[i]["title"]=Gdata[i]["name"]  
 Gdata[i]["category"]=Gdata[i]["types"][1]  
 print ( "title: " .. Gdata[i]["title"] )  
 print ( "category: " .. Gdata[i]["category"] )  
 i=i+1  
 end--do  
 print ( "RESPONSE:LAT: " .. testValue )  
 print ( "RESPONSE:LNG: " .. testValue2 )  
 ReFresh()  
 end  
 end  
end  
  
--call to request a list of places  
local function RequestPlaces(lLat,lLng)  
 local lRadius = 500 --update from user defined range  
 local lTypes = "bar|convenience\_store|liquor\_store"--update from user defined filter  
 local lSensor= "true"  
 local lKey = "Sorry\_not\_sharing\_my\_key"  
 network.request( "https://maps.googleapis.com/maps/api/place/search/json?location="..lLat..","..lLng.."&radius=".. lRadius.."&types="..lTypes.."&sensor="..lSensor.."&key="..lKey, "GET", networkListener )  
 print("requested")  
return true  
end  
  
x = RequestPlaces(currentLatitude,currentLongitude)  
print("DONE")  

Any insight anyone can give me would be greatly appreciated. [import]uid: 40100 topic_id: 14177 reply_id: 314177[/import]

The listener does fire… a response can be captured from other URL’s … this URL works in the simulator and not on the device…

I am at a loss as to why this does not work. Has anyone else successfully made a request to Google’s places api using Corona?
(Maybe there is something in the response that causes it to fail on the device? Illegal characters or some such?)
Update:
hmm… path works when pasted into the browser on the device…

When the request is sent by Corona does it send it in the same case as what the string is formated? (If it converts CAPS to lowercase it could be causing my api key to fail)

…(I’ll continue to mutter to myself and pull my hair out)… [import]uid: 40100 topic_id: 14177 reply_id: 52767[/import]

… still nothing… I tried saving the result to a file(used the asynch http image download sample app) and it again works in the simulator and not on the device… looking at the traffic for the API (tracked by my key) it never recieves the request when it is running on the device. So… the request is never sent from the device or the request is somehow malformed when it is sent from the device. (It would have to be something that would only effect some url’s.)

…(very little hair left and have now been fitted for my strait jacket)…
[import]uid: 40100 topic_id: 14177 reply_id: 53465[/import]

Hi.

I have the same problem. I user network.request work fine on simulator but not in my phone (iphone 4).

I dont understand where is my error.

I you know how solve this problem please post the response…

[import]uid: 12275 topic_id: 14177 reply_id: 54797[/import]

Still scratching my head on this (ok… I gave up on my app that uses this for now.) I have tried the most recent builds and still no joy. Have entered a support request… no usefull response… :frowning: … would be nice if someone from Ansca would comment ( I would like a meaningfull comment not just a quick quip.) [import]uid: 40100 topic_id: 14177 reply_id: 55109[/import]

Did you verify your internet settings are configured correctly on your device? Also, we don’t support proxy servers.

We have 3 different automated tests that test our async network stuff and they have been passing. We haven’t changed the code in a long while either, so I’m not sure why things aren’t working for you.

Below is what one of our tests looks like:

[code]
require(‘CoronaTest’)

local goodURL = “http://developer.anscamobile.com/sites/default/files/test.txt
local badURL = “666.66.66.666”
local secureURL = “https://encrypted.google.com
local postURL = “http://www.anscamobile.com/formecho.php

local url = goodURL

local responseData_known = “Test file contents.”
local postResponse_known = “red small.”

local postData = “color=red&size=small”
local params = {}
params.body = postData
params.headers = nil

local NUMBER_OF_TESTS = 7
plan(NUMBER_OF_TESTS)

local function networkListener( event )
if url == badURL then
is( event.isError, true, “Checking for request error - bad URL” )
– Make post data request
diag(“making POST request”)
callPostURL()
– EndTest()
else
isnt( event.isError, true, "Checking for request error - good URL " )
diag(“parsing response”)
is(event.response, responseData_known, “Checking downloaded text.”)
callBadURL()
end
end

local function postDataListener( event )
if ( event.isError ) then
print( “Error with POST”)
else
is(event.response, postResponse_known, “Checking downloaded text.”)

– print ( "Post RESPONSE: " … event.response )
end
isnt( event.isError, true, "Checking for POST request error " )
callSecureURL()
end

local function secureNetworkListener( event )
isnt( event.isError, true, "Checking for SSL request error " )
if ( event.isError ) then
diag(“Error with SSL response/request”)
else
– print ( "RESPONSE: " … event.response )
ok(event.response ~= nil, “Checking for non-nil SSL response.”)
end
EndTest()
end

function callBadURL( )
url = badURL
diag(“Calling bad URL”)
network.request(badURL, “GET”, networkListener)
end

function callPostURL ()
diag(“Calling POST URL”)
url = postURL
network.request( url, “POST”, postDataListener, params)
end

function callSecureURL ()
diag(“Calling SSL URL”)
url = secureURL
– Access Google over SSL:
network.request( url , “GET”, secureNetworkListener )

end

function EndTest()
done_testing(NUMBER_OF_TESTS)
os.exit()
end

network.request(goodURL, “GET”, networkListener)
[/code] [import]uid: 7563 topic_id: 14177 reply_id: 55130[/import]

I solve the problem.

Corona work fine, the error is in the webservice or the web app.

For any reason some responses from the server (i dont know why) generate a error for example y request 5 valuse from my web service but the first value have something (maybe wrong charracters or something) then the first value generate a error then the other 4 values dont load. The app work on simulator but not in the phone. Then i trim the first value and then work fine in both devices.

My recomendation test the app with a text file /yourdomain/test.txt try to load this and you see the app work fine in mobile and simulator.
[import]uid: 12275 topic_id: 14177 reply_id: 55351[/import]

From my privous post:

(Maybe there is something in the response that causes it to fail on the device? Illegal characters or some such?)

Update:
hmm… path works when pasted into the browser on the device…

When the request is sent by Corona does it send it in the same case as what the string is formated? (If it converts CAPS to lowercase it could be causing my api key to fail)

My internet settings are configured correctly.(it does work with other URL’s)
I am NOT using a proxy server.
The url is valid (works in simulator and when posted into any browser, on the device or otherwise)

The google places API is NOT recieving the request from my Corona app when built for the device. (at least not tracked to my API key)

This leads me to believe that something is amiss with the way the request is sent from a Corona app when built for an android device(no idea if this is an issue with iOS).

Looking at the test… it AGAIN makes me wonder if the request on the device converts the URL to lower case before sending it. (the API key in my network request IS case sensitive).

Example:

local goodURL = "http://developer.anscamobile.com/sites/default/files/TEST.txt"

Would this ask for a file named “TEST.txt” or “test.txt”? (yes, I know in that situation it should not matter, most situations it would not matter, my situation, it matters a lot.) [import]uid: 40100 topic_id: 14177 reply_id: 55546[/import]

I checked your sample code on both the Windows and Mac Simulator and an Android device (Nexus One) and found the listener was called every time. I had to enable your “Network Error!” print statement to see that it responded with an error in both the Mac Simulator and Android device. The Windows Simulator didn’t response with an error.

The problem I found was because of this line:
local lTypes = “bar|Cconvenience_store|liquor_store”–update from user defined filter

The “|” characters were causing the error and need to be escaped. Here is my change:
local lTypes = “bar%7Cconvenience_store%7Cliquor_store”–update from user defined filter

With the above change, both simulators and Android send the URL with all the parameters. I didn’t check it with google maps but I did verify it by sending it to a postbin.org URL. That showed the URL and all the parameters were correctly sent.

You need to be careful when you include characters in a URL because there are number of them that are special. You can Google URL Character Encoding to find out more.

Update:
Here is the response I saw in the postbin.org page after running the app on the Nexus One (I created fake lat/long values):

#1qrcrp @ 21:26 Sep 12 2011 -- 153.7.111.236 ?location=123.175,999.876&radius=500&types=bar%7Cconvenience\_store%7Cliquor\_store&sensor=true&key=Sorry\_not\_sharing\_my\_keyContent  
key Sorry\_not\_sharing\_my\_key  
location 123.175,999.876  
radius 500  
sensor true  
types bar|convenience\_store|liquor\_store  
  

-Tom [import]uid: 7559 topic_id: 14177 reply_id: 55584[/import]

Thank you very much… that did it…

I never EVER would have thought to escape the pipe. |-) [import]uid: 40100 topic_id: 14177 reply_id: 55613[/import]

@allen.holtzapfel

I am trying to use Google places myself to “check in” and I came across your post. I wonder if you could help me out. I do not need to display any maps just do the “check in”. Any help to point me in the right direction would be greatly appreciated.

Thanks [import]uid: 95689 topic_id: 14177 reply_id: 93314[/import]