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
Release: 2024-10-28 12:04:55
Original
573 people have browsed it

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

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!