为什么我无法以json的形式从Web服务器检索数据,但是在localhost上进行测试时却可以 [英] Why I can't retrieve data from my webserver as json but i can when i test it on localhost

查看:88
本文介绍了为什么我无法以json的形式从Web服务器检索数据,但是在localhost上进行测试时却可以的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个连接到mysql数据库的简单登录应用程序. 当我在localhost中对其进行测试时,该应用程序可以正常工作,但是当我将数据库和php脚本上载到托管服务器(Byethost)时,它无法正常工作, 问题似乎来自服务器的响应字符串,它不是"JSON"

I'm trying to create a simple login app that connects to mysql database. The app works find when i test it in localhost , but when i uploaded the database and the php scripts to a Hosting server ( Byethost ) it is not working, the problem seems with the response string form the server, it is not "JSON"

如上所述,当我在localhost中测试应用程序时,它就可以正常工作.

as i mentioned above, when i test the application in localhost it works just fine.

        requestQueue = Volley.newRequestQueue(this);
    StringRequest stringRequest = new StringRequest(Request.Method.POST, login_url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            try{
                Log.d("#-SERVER RESPONSE-#",response);
                JSONObject jsonObject = new JSONObject(response);
                Log.d("#-LOGIN STATUS-#",jsonObject.getString("status"));
            } catch (Exception e){
                Log.d("#-JSON ERROR-#",e.toString());
            }//end if
        }
    },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.d("#-VOLLEY ERROR-#",error.toString());
                }
            }){

        @Override
        public Map<String,String> getParams(){
            Map<String,String> params = new HashMap<>();
            params.put(KEY_USERNAME,username);
            params.put(KEY_PASSWORD,password);
            return params;
        }
    };
    requestQueue.add(stringRequest);

这是php代码

    $username = mysqli_real_escape_string($connection,$_POST['username']);
$password = mysqli_real_escape_string($connection,$_POST['password']);

$query = "SELECT * FROM user WHERE username='{$username}' AND password='{$password}'";
$result = mysqli_query($connection,$query);

$json_reply['status'] = 1; //erorr by default

if(mysqli_num_rows($result) > 0){
  $json_reply['status'] = 0; //success
}

print(json_encode($json_reply));

这是Android Monitor窗口的输出.

<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("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("99efa97c59e1cf6146f7e801802ed6bc");document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/"; document.cookie="referrer="+escape(document.referrer); location.href="http://zsoft.byethost8.com/login.php?ckattempt=1";</script><noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support</noscript></body></html>

推荐答案

似乎问题出在主机本身上,我尝试了另一台主机(arvixe),并且一切正常.我不知道为什么,但也许是因为这是付费托管.

Seems the problem was with the hosting itself, I tried another hosting (arvixe) and everything works as charm. i have no idea why but maybe because it is a payed hosting.

这篇关于为什么我无法以json的形式从Web服务器检索数据,但是在localhost上进行测试时却可以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆