Home >Backend Development >PHP Tutorial >Why is My Android App Receiving HTML Instead of JSON from a ByetHost Server?
ByetHost Server Passing HTML Values "Checking Your Browser" with JSON String
Problem
When trying to parse a JSON string on Android, HTML values are returned instead. This sudden issue affects all pages hosted on the ByetHost server, while pages hosted on other servers work properly.
Solution
The issue arises due to the ByetHost server implementing the testcookie-nginx-module security anti-bot measure. This module performs a two-step validation process:
Steps to Resolve the Issue for Android Apps
Obtain the Cookie Key from a Web Browser:
In the HTTP request code of your app, add a header below to include the "__test" cookie:
<code class="java">httpPost.addHeader("Cookie", "__test=THE_CONTENT_OF_YOUR_COOKIE_HERE; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/");</code>
Replace "THE_CONTENT_OF_YOUR_COOKIE_HERE" with the "content" value obtained in step 1.
With these changes, the Android app will include the "__test" cookie in its HTTP requests, allowing it to access the desired JSON responses from the ByetHost server.
The above is the detailed content of Why is My Android App Receiving HTML Instead of JSON from a ByetHost Server?. For more information, please follow other related articles on the PHP Chinese website!