Why Am I Receiving A Json Exception Trying To Load Data From Host Url?
Solution 1:
The problem is that the web host that I am utilizing (Byet Host) implements a simple security antibots module named testcookie-nginx-module for L7 DDoS attack mitigation.
https://kyprizel.github.io/testcookie-nginx-module/
The testcookie-nginx-module makes a 2-step validation:
1) The first time that a HTTP request is done, the module returns a javascript instead of the JSON we are expecting. This script is executed on the client (tipically a web browser) and generates a validation cookie containing an AES key.
2) The script adds the validation cookie to the document and redirects it to the url we actually want to access. The testcookie-nginx-module validates the cookie AES key and lets the request hit the url that will respond with the JSON data we want to access. On the following HTTP requests the client will have stored the cookie and will add it to the request skipping the step 1.
We just need to add a cookie to the HTTP request to pass the testcookie-nginx-module.
These links should help optimize the code and aid future developers with the same issue:
ByetHost server passing html values "Checking your browser" with JSON String
and
Add cookie to client request OkHttp
:-)
Simply calling .addHeader worked for me.
@OverrideprotectedVoiddoInBackground(Integer... integers) {
OkHttpClient client = newOkHttpClient();
Request request = newRequest.Builder()
.url("http://thebeerguru.byethost13.com/conn_all.php?id="+id)
.addHeader("Cookie", "__test=THE_CONTENT_OF_MY_COOKIE; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/")
.build();
try {
Response response = client.newCall(request).execute();
JSONArray array = newJSONArray(response.body().string());
Thanks to everyone for their counsel and support!
Post a Comment for "Why Am I Receiving A Json Exception Trying To Load Data From Host Url?"