0

I'm implementing an application that does REST calls to a server to get a JSON response. If I do these calls connected to my home's Wi-Fi connection I get the result WITHOUT headers:

{"id":"ohig40o45h6c2a5d9rdhsft2v7","module_name":"Users", ...}

But if I do these calls using my phone's 3G connection I get the response with all the headers:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"        
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title></title>
        </head>
        <body>
            <pre xml:space="preserve">
                 {"id":"ohig40o45h6c2a5d9rdhsft2v7","module_name":"Users", ...}
            </pre>
        </body>
     </html>

I want to get the body message (without the "pre" tags). Is there an easy way to do it? Why do I get the headers only if I use 3G connection?

Thanks.

jhonkola
  • 3,385
  • 1
  • 17
  • 32
PX Developer
  • 8,065
  • 7
  • 42
  • 66
  • These are not http headers, but html. The first response in just the JSON, and the second has the JSON wrapped in html. Is the web service controlled by you? – jhonkola Aug 10 '12 at 06:01

1 Answers1

0

I know it's an old question, but I had the same problem and here is the solution:

Just add at the beginning of your webservice the headers to inform that the response is JSON. If you are using PHP here is the example:

<?
header('Content-type: application/json');

//Your webservice code here
?>

Hope it helps!!

  • 1
    it is considered poor practice to use the short `` PHP tag. One should generally always use the long form ` – Spudley Aug 31 '12 at 21:37