Home  >  Article  >  Backend Development  >  The following are several English titles suitable for the content of the article, presented in a question and answer format: 1. Why is my Android app receiving HTML instead of JSON data from a ByeHost server? 2. How do I fix the \"Checking Your Browser\" error when fetching JSON data fro

The following are several English titles suitable for the content of the article, presented in a question and answer format: 1. Why is my Android app receiving HTML instead of JSON data from a ByeHost server? 2. How do I fix the \"Checking Your Browser\" error when fetching JSON data fro

Linda Hamilton
Linda HamiltonOriginal
2024-10-28 12:04:55574browse

以下是几个适合文章内容的英文标题,以问答形式呈现:

1. Why is my Android app receiving HTML instead of JSON data from a ByeHost server?
2. How do I fix the

ByeHost Server Sending HTML Values ​​"Checking Your Browser" with JSON String

Question:

When trying to parse a JSON string to Android, HTML values ​​are passed. Everything was functioning fine until a day ago, but suddenly when trying to get the database using a PHP file, my application started crashing.

When I checked, noticed the HTML value, see logcat.

Answer:

The solution is:

  1. Add Cookie to HTTP request:

ByeHost uses an antibots security module called testcookie-nginx-module. This module performs two-step verification on HTTP requests:

Step 1: On the first request, the module returns a JavaScript that generates the verification cookie.

Step 2: On subsequent requests, the client will add the authentication cookie and the module will verify the cookie AES key and allow the request to continue.

  1. Get the cookie key and add it to the Android request:
  • Use a web browser to visit the URL once to generate the cookie .
  • Get the value of __test Cookie from the web browser.
  • In Android applications, add Cookie headers to HTTP requests.
<code class="java">httpPost.addHeader("Cookie", "__test=THE_CONTENT_OF_YOUR_COOKIE_HERE; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/");</code>

With these steps, the application will include cookies to pass validation and the expected JSON data can be retrieved.

The above is the detailed content of The following are several English titles suitable for the content of the article, presented in a question and answer format: 1. Why is my Android app receiving HTML instead of JSON data from a ByeHost server? 2. How do I fix the \"Checking Your Browser\" error when fetching JSON data fro. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn