• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps nil web service values

Not completely sure what you are looking for here but start with the simple... Take a look at the raw HTTP response from the web service call before attempting to parse. Are you getting a valid return from the WS or are you getting an error like a 400+ or 500+ http response code? Next, if you are getting a 200 make sure you are receiving a valid JSON string. Debug and step through the code to see what you are getting back. Is the issue server side or client side?
 
Upvote 0
Not completely sure what you are looking for here but start with the simple... Take a look at the raw HTTP response from the web service call before attempting to parse. Are you getting a valid return from the WS or are you getting an error like a 400+ or 500+ http response code? Next, if you are getting a 200 make sure you are receiving a valid JSON string. Debug and step through the code to see what you are getting back. Is the issue server side or client side?

I received a JSON response. The WS returns a value of -1 for the userid if it can't find the user requested in the database. If you're on the server and you're stepping through the WS code as it is executed, the entity received by the WS is nil. It doesn't have a JSON string to parse. I stepped through the code in my Android application and I build the JSON string to send correctly and I give it to the httpPost object and it hits the WS code. But by this point the data is lost somewhere...
 
Upvote 0
I received a JSON response. The WS returns a value of -1 for the userid if it can't find the user requested in the database. If you're on the server and you're stepping through the WS code as it is executed, the entity received by the WS is nil. It doesn't have a JSON string to parse. I stepped through the code in my Android application and I build the JSON string to send correctly and I give it to the httpPost object and it hits the WS code. But by this point the data is lost somewhere...


Hope I am understanding you correctly. It sounds like the JSON is not being parametrized properly. Before calling the "response = httpClient.execute(httpPost, localContext); inspect that httpPost object to make sure the JSON is valid and parametrized properly. Then debug on the server and look at the raw HTTP request, just as it arrives, headers and all to make sure the JSON is there. If the JSON is not there than either it was not posted or the web server is stripping it for some reason. If all else fails, stop adding the JSON for a moment and just add a plain ole query string variable and see if that at least makes it to the WS.
 
Upvote 0
Here is the traffic



This is the working iPhone calling the WS:
Code:
5:.POST /api/login.php HTTP/1.1
Host: www.mydomain.com
User-Agent: MyDomain/1.0 CFNetwork/485.2 Darwin/10.4.0
Content-Type: application/x-www-form-urlencoded
Accept: */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Content-Length: 100
Connection: keep-alive


11:47:54.698252 IP xxx.xxx.xxx.xxx.62061 > dev.local.www: Flags [P.], seq 283:383, ack 1, win 65535, options [nop,nop,TS val 722618086 ecr 171260420], length 100
E...r.@.?..l
...
..i.m.P....f.......'......
+.F.
5:.&json={"email":"me@mydomain.com","password":"8bfeb7b030ae1994f504c6c9ec46111b90434378"}
11:47:54.708328 IP dev.local.www > xxx.xxx.xxx.xxx.62061: Flags [P.], seq 1:445, ack 383, win 54, options [nop,nop,TS val 171260425 ecr 722618086], length 444
E...&.@.@..P
..i
....P.mf..........6.......

5: *****+.F.HTTP/1.1 200 OK
Date: Tue, 20 Jul 2010 16:47:54 GMT
Server: Apache/2.2.15 (Debian)
X-Powered-By: PHP/5.3.2-1
Set-Cookie: dr=deleted; expires=Mon, 20-Jul-2009 16:47:53 GMT
Cache-Control: no-cache, must-revalidate
Expires: Sat, 26 Jul 1997 05:00:00 GMT
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 35
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html

...........V*-N-..LQ.R2R....t......



This is the not working Android calling the WS:
Code:
;..POST /api/login.php HTTP/1.1
Accept: */*
Content-Type: application/json
Accept-Language: en-us
Accept-Encoding: application/json
Content-Length: 69
Content-Type: json
Host: www.mydomain.com
Connection: Keep-Alive

json={"email":"me@mydomain.com","password":"copernicus"}
12:16:19.757757 IP dev.local.www > xxx.xxx.xxx.xxx.49694: Flags [P.], seq 1:337, ack 297, win 54, options [nop,nop,TS val 171686687 ecr 607133898], length 336
E...@.@.@..O
..i
....P......1......6.......

;..$0 .HTTP/1.1 200 OK
Date: Tue, 20 Jul 2010 17:16:19 GMT
Server: Apache/2.2.15 (Debian)
X-Powered-By: PHP/5.3.2-1
Cache-Control: no-cache, must-revalidate
Expires: Sat, 26 Jul 1997 05:00:00 GMT
Vary: Accept-Encoding
Content-Length: 14
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html

{"user_id":-1}


Note that the not working Android traffic is clearly not sending a hashed password, but that is besides the point. The POST data is nil when debugging the web service. It can't grab a post body...
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones