nil web service values


Last Updated:

  1. andywhoa

    andywhoa Well-Known Member This Topic's Starter

    Joined:
    May 15, 2010
    Messages:
    105
    Likes Received:
    13

    Advertisement
  2. android2dev

    android2dev Active Member

    Joined:
    Jul 15, 2010
    Messages:
    32
    Likes Received:
    4
    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?
     
  3. andywhoa

    andywhoa Well-Known Member This Topic's Starter

    Joined:
    May 15, 2010
    Messages:
    105
    Likes Received:
    13
    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...
     
  4. android2dev

    android2dev Active Member

    Joined:
    Jul 15, 2010
    Messages:
    32
    Likes Received:
    4

    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.
     
  5. andywhoa

    andywhoa Well-Known Member This Topic's Starter

    Joined:
    May 15, 2010
    Messages:
    105
    Likes Received:
    13
    Watching the traffic it sends the JSON in the first packet, with some garbage below it.

    In the iPhone app I have (that works fine), it sends it in the second packet, with some garbage above it
     
  6. andywhoa

    andywhoa Well-Known Member This Topic's Starter

    Joined:
    May 15, 2010
    Messages:
    105
    Likes Received:
    13
    Here is the traffic



    This is the working iPhone calling the WS:
    Code (Text):
    1. 5:.POST /api/login.php HTTP/1.1
    2. Host: www.mydomain.com
    3. User-Agent: MyDomain/1.0 CFNetwork/485.2 Darwin/10.4.0
    4. Content-Type: application/x-www-form-urlencoded
    5. Accept: */*
    6. Accept-Language: en-us
    7. Accept-Encoding: gzip, deflate
    8. Content-Length: 100
    9. Connection: keep-alive
    10.  
    11.  
    12. 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
    13. E...r.@.?..l
    14. ...
    15. ..i.m.P....f.......'......
    16. +.F.
    17. 5:.&json={"email":"me@mydomain.com","password":"8bfeb7b030ae1994f504c6c9ec46111b90434378"}
    18. 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
    19. E...&.@.@..P
    20. ..i
    21. ....P.mf..........6.......
    22.  
    23. 5: *****+.F.HTTP/1.1 200 OK
    24. Date: Tue, 20 Jul 2010 16:47:54 GMT
    25. Server: Apache/2.2.15 (Debian)
    26. X-Powered-By: PHP/5.3.2-1
    27. Set-Cookie: dr=deleted; expires=Mon, 20-Jul-2009 16:47:53 GMT
    28. Cache-Control: no-cache, must-revalidate
    29. Expires: Sat, 26 Jul 1997 05:00:00 GMT
    30. Vary: Accept-Encoding
    31. Content-Encoding: gzip
    32. Content-Length: 35
    33. Keep-Alive: timeout=15, max=100
    34. Connection: Keep-Alive
    35. Content-Type: text/html
    36.  
    37. ...........V*-N-..LQ.R2R....t......


    This is the not working Android calling the WS:
    Code (Text):
    1. ;..POST /api/login.php HTTP/1.1
    2. Accept: */*
    3. Content-Type: application/json
    4. Accept-Language: en-us
    5. Accept-Encoding: application/json
    6. Content-Length: 69
    7. Content-Type: json
    8. Host: www.mydomain.com
    9. Connection: Keep-Alive
    10.  
    11. json={"email":"me@mydomain.com","password":"copernicus"}
    12. 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
    13. E...@.@.@..O
    14. ..i
    15. ....P......1......6.......
    16.  
    17. ;..$0 .HTTP/1.1 200 OK
    18. Date: Tue, 20 Jul 2010 17:16:19 GMT
    19. Server: Apache/2.2.15 (Debian)
    20. X-Powered-By: PHP/5.3.2-1
    21. Cache-Control: no-cache, must-revalidate
    22. Expires: Sat, 26 Jul 1997 05:00:00 GMT
    23. Vary: Accept-Encoding
    24. Content-Length: 14
    25. Keep-Alive: timeout=15, max=100
    26. Connection: Keep-Alive
    27. Content-Type: text/html
    28.  
    29. {"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...
     
  7. andywhoa

    andywhoa Well-Known Member This Topic's Starter

    Joined:
    May 15, 2010
    Messages:
    105
    Likes Received:
    13
    I figured it out.

    I was missing an ampersand :|

    There goes 6 hours of my life
     
  8. android2dev

    android2dev Active Member

    Joined:
    Jul 15, 2010
    Messages:
    32
    Likes Received:
    4
    Bang....and there it is. Yup...that's how it goes in software engineering. Glad you got it figured out.
     

Share This Page

Loading...