php–ByetHost服务器使用JSON字符串传递html值“检查您的浏览器”

php–ByetHost服务器使用JSON字符串传递html值“检查您的浏览器”,第1张

概述在尝试将json字符串解析为android时,会传递HTML值.在一天之前一切都很好,突然我的应用程序在尝试使用php文件获取数据库时开始崩溃.当我检查注意到html值..看看logcat08-1001:09:55.814:Eesult(6744):<html><body><h2>Checkingyourbrowser..<h2><scripttype="text/java

在尝试将Json字符串解析为android时,会传递HTML值.
在一天之前一切都很好,突然我的应用程序在尝试使用PHP文件获取数据库时开始崩溃.

当我检查注意到HTML值..
看看logcat

08-10 01:09:55.814: E/result(6744): <HTML><body><h2>Checking your browser..<h2><script type="text/JavaScript" src="/aes.Js" ></script><script>function toNumbers(d){var e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return e.tolowerCase()}var a=toNumbers("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("7965e114a1dccaf35af3756261f75ad8");document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/";location.href="http://realroom.byethost24.com/medical/stokist.PHP?ckattempt=1";</script></body></HTML>08-10 01:09:55.814: E/JsON Parser(6744): Error parsing data org.Json.JsONException: Value <HTML><body><h2>Checking of type java.lang.String cannot be converted to JsONObject08-10 01:09:55.816: E/AndroIDRuntime(6744): FATAL EXCEPTION: AsyncTask #108-10 01:09:55.816: E/AndroIDRuntime(6744): Process: com.example.medionline, PID: 674408-10 01:09:55.816: E/AndroIDRuntime(6744): java.lang.RuntimeException: An error occured while executing doInBackground()08-10 01:09:55.816: E/AndroIDRuntime(6744):     at androID.os.AsyncTask.done(AsyncTask.java:304)08-10 01:09:55.816: E/AndroIDRuntime(6744):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)08-10 01:09:55.816: E/AndroIDRuntime(6744):     at java.util.concurrent.FutureTask.setException(FutureTask.java:222)08-10 01:09:55.816: E/AndroIDRuntime(6744):     at java.util.concurrent.FutureTask.run(FutureTask.java:242)08-10 01:09:55.816: E/AndroIDRuntime(6744):     at androID.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)08-10 01:09:55.816: E/AndroIDRuntime(6744):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)08-10 01:09:55.816: E/AndroIDRuntime(6744):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)08-10 01:09:55.816: E/AndroIDRuntime(6744):     at java.lang.Thread.run(Thread.java:818)08-10 01:09:55.816: E/AndroIDRuntime(6744): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.Json.JsONObject.toString()' on a null object reference08-10 01:09:55.816: E/AndroIDRuntime(6744):     at com.example.medionline.All_supplier_List$FetchMFG.doInBackground(All_supplier_List.java:182)08-10 01:09:55.816: E/AndroIDRuntime(6744):     at com.example.medionline.All_supplier_List$FetchMFG.doInBackground(All_supplier_List.java:1)08-10 01:09:55.816: E/AndroIDRuntime(6744):     at androID.os.AsyncTask.call(AsyncTask.java:292)08-10 01:09:55.816: E/AndroIDRuntime(6744):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)08-10 01:09:55.816: E/AndroIDRuntime(6744):     ... 4 more

这发生在我托管在服务器上的所有页面上,而托管在其他服务器上的页面运行良好.我尝试将我的一个文件移动到其他服务器,并且它正在返回正确的Json字符串.

此外,当我检查浏览器中的URL时,它返回正确的Json字符串,没有任何异常或错误与byethost ..但在androID给出HTML值..

这是我的JsONfunction类

package com.example.medionline;import java.io.BufferedReader;import java.io.IOException;import java.io.inputStream;import java.io.inputStreamReader;import java.io.UnsupportedEnCodingException;import java.util.List;import org.apache.http.httpentity;import org.apache.http.httpResponse;    import org.apache.http.nameValuePair;import org.apache.http.clIEnt.ClIEntProtocolException;import org.apache.http.clIEnt.httpClIEnt;import org.apache.http.clIEnt.entity.UrlEncodedFormEntity;import org.apache.http.clIEnt.methods.httpGet;import org.apache.http.clIEnt.methods.httpPost;import org.apache.http.clIEnt.utils.URLEncodedUtils;import org.apache.http.impl.clIEnt.DefaulthttpClIEnt;import org.Json.JsONException;import org.Json.JsONObject;import androID.util.Log;public class JsONfunctions{     static inputStream is = null; static String result = ""; static JsONObject jArray = null;public static JsONObject getJsONfromURL(String url) {    // Download JsON data from URL    try     {        httpClIEnt httpclIEnt = new DefaulthttpClIEnt();        httpPost httppost = new httpPost(url);        httppost.setheader("User-Agent","Mozilla/5.0 (windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240 ");        httpResponse response = httpclIEnt.execute(httppost);        httpentity entity = response.getEntity();        is = entity.getContent();    }     catch (Exception e)     {        Log.e("log_tag", "Error in http connection " + e.toString());    }    try     {        BufferedReader reader = new BufferedReader(new inputStreamReader(is, "iso-8859-1"), 8);        StringBuilder sb = new StringBuilder();        String line = null;        while ((line = reader.readline()) != null)         {            Log.e("Jsonnnnnnn", line);            sb.append(line + "\n");        }        is.close();        result = sb.toString();        Log.e("result", result);    }     catch (Exception e)     {        Log.e("log_tag", "Error converting result " + e.toString());    }    try     {        jArray = new JsONObject(result);    }     catch (JsONException e)    {        Log.e("log_tag", "Error parsing data " + e.toString());    }    return jArray;}public static JsONObject makehttpRequest(String loginUrl, String post, List<nameValuePair> para){    try     {        if(post == "POST")        {            httpClIEnt httpClIEnt = new DefaulthttpClIEnt();            httpPost httpPost = new httpPost(loginUrl);            httpPost.setEntity(new UrlEncodedFormEntity(para));            httpPost.setheader("User-Agent","Mozilla/5.0 (windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240 ");            httpResponse httpResponse = httpClIEnt.execute(httpPost);            httpentity httpentity = httpResponse.getEntity();            is = httpentity.getContent();        }        else if(post == "GET")        {            httpClIEnt httpClIEnt = new DefaulthttpClIEnt();            String paramString = URLEncodedUtils.format(para, "utf-8");            loginUrl += "?" + paramString;            httpGet httpGet = new httpGet(loginUrl);            httpResponse httpResponse = httpClIEnt.execute(httpGet);            httpentity httpentity = httpResponse.getEntity();            is = httpentity.getContent();        }    }    catch (UnsupportedEnCodingException e)    {        e.printstacktrace();    }    catch (ClIEntProtocolException e)    {        e.printstacktrace();    }    catch (IOException e)    {        e.printstacktrace();    }    try     {        BufferedReader reader = new BufferedReader(new inputStreamReader(is, "utf-8"), 8);        StringBuilder sb = new StringBuilder();        String line = null;        if (is != null)         {            while ((line = reader.readline()) != null)             {                //Log.e("Jsonnnnnnn", line);                sb.append(line + "\n");            }            is.close();            result = sb.toString();            Log.e("result", result);        }    }    catch (Exception e)    {        Log.e("Buffer Error", "Error converting result " + e.toString());    }    try    {        jArray = new JsONObject(result);    }    catch (JsONException e)    {        Log.e("JsON Parser", "Error parsing data " + e.toString());    }    return jArray;}}

这是我的PHP文件

<?PHPinclude('config.PHP');date_default_timezone_set("Asia/Calcutta");$result1 = MysqLi_query($con,"SELECT  *                                    FROM  `pj_medionline_mst_stockist`                                     ORDER BY  `pj_medionline_mst_stockist`.`ID` ASC ");$response = array();$posts = array();while($row=MysqLi_fetch_array($result1)){    $ID =$row["ID"];    $stkcode =$row["stkcode"];    $comname =$row["Comname"];    $operatorID =$row["operatorID"];    $password =$row["Password"];    $posts[] = array('ID'=>$ID, 'stkcode'=>$stkcode, 'stkname'=>$comname, 'operatorID'=>$operatorID, 'password'=>$password);}$response['stokist'] = $posts;print(Json_encode($response));?>

解决方法:

解决了!

我使用Byethost从PHP服务器检索JsON数据时遇到了同样的问题.我们只需要在http请求中添加一个cookie来传递testcookie-Nginx-module

正如理查德的answer所说:

The main problem is that Byet Host implement a simple security antibots module >named testcookie-Nginx-module

07001

在他提供的链接上,我们可以看到testcookie-Nginx-module进行了两步验证:

>第一次完成http请求时,模块返回一个JavaScript而不是我们期望的JsON.此脚本在客户端(通常是Web浏览器)上执行,并生成包含AES密钥的验证cookie.

这是我从服务器收到的脚本:

<HTML><body>    <script type="text/JavaScript" src="/aes.Js" ></script>    <script>        function toNumbers(d){        var e=[];            d.replace(/(..)/g,function(d){                e.push(parseInt(d,16))});            return e        }        function toHex(){            for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++)                e+=(16>d[f]?"0":"")+d[f].toString(16);                return e.tolowerCase()        }        var a=toNumbers("f655ba9d09a112ffff8c63579db590b4"),            b=toNumbers("98344c2eee86c3ffff90592585b49f80"),            c=toNumbers("1286963467aa92ffff8323bdca0d7be9");        document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/";         location.href="http://myserver.byethost8.com/myPHPPage.PHP?i=1";    </script>    <noscript>This site requires JavaScript to work, please enable JavaScript in your browser or use a browser with JavaScript support</noscript></body>

>该脚本将验证cookie添加到文档中,并将其重定向到我们实际想要访问的URL. testcookie-Nginx-module验证cookie AES密钥,并让请求到达将响应我们想要访问的JsON数据的url.

在以下http请求中,客户端将存储cookie并将其添加到跳过步骤1的请求中.

我们的AndroID应用程序解决方案

我们将通过从Web浏览器获取cookie并将其直接添加到我们的AndroID http请求中来跳过cookie生成(除非您当然希望参与生成它).

在从Web浏览器获取cookie之前,请确保使用浏览器至少访问过一次url以生成它.

>从Web浏览器获取cookie密钥.我使用谷歌浏览器:

>从浏览器右上角的Chrome菜单中,选择设置.
>在页面底部,单击显示高级设置….
>在隐私下,选择内容设置….
>选择所有cookie和网站数据….
>搜索您的网站名称.通过搜索“byethost”你会找到它.
>打开名为__test的cookie并复制内容,路径和过期的值

>在我们的AndroID应用程序上设置cookie.你的代码应该是这样的:

try { if(post == "POST") {     httpClIEnt httpClIEnt = new DefaulthttpClIEnt();     httpPost httpPost = new httpPost(loginUrl);     httpPost.setEntity(new UrlEncodedFormEntity(para));     httpPost.setheader("User-Agent","Mozilla/5.0 (windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240 ");     httpPost.addheader("cookie", "__test=THE_CONTENT_OF_YOUR_cookie_HERE; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/");     httpResponse httpResponse = httpClIEnt.execute(httpPost);     httpentity httpentity = httpResponse.getEntity();     is = httpentity.getContent();}else if(post == "GET"){    httpClIEnt httpClIEnt = new DefaulthttpClIEnt();    String paramString = URLEncodedUtils.format(para, "utf-8");    loginUrl += "?" + paramString;    httpGet httpGet = new httpGet(loginUrl);    httpGet.addheader("cookie", "__test=THE_CONTENT_OF_YOUR_cookie_HERE; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/");    httpResponse httpResponse = httpClIEnt.execute(httpGet);    httpentity httpentity = httpResponse.getEntity();    is = httpentity.getContent();}}

就是这样.现在每次应用程序发出http请求时,它都会包含cookie以传递testcookie-Nginx-module并将检索您的JsON数据.

我希望这有所帮助,并且为时不晚.

问候

总结

以上是内存溢出为你收集整理的php – ByetHost服务器使用JSON字符串传递html值“检查您的浏览器”全部内容,希望文章能够帮你解决php – ByetHost服务器使用JSON字符串传递html值“检查您的浏览器”所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1103674.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存