douna1895 2015-06-27 16:22
浏览 71
已采纳

当我尝试从Android应用程序中的PHP脚本恢复数据时访问被拒绝403

I have a php script called query3.php that returns the max punctuations from an Android game, stored in a mysql database.

It worked perfectly til today, but now it returns Access denied err403. I haven't made any changes in the code.

The curious thing is that if I enter the url in a browser, it works ok, and I see the JSON encoded data. The problem occurs only when I access from my Android App.

In the Access logs of the database it appears like this:

xxxxxxxxxxxxxxxx.com [27/Jun/2015:10:48:42 -0500] 90.174.2.74 - - "POST /query3.php HTTP/1.1" 403 18 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"

It might be something new they configured in the server?. I wrote to them but didn't get response yet.

  • 写回答

1条回答 默认 最新

  • doushi3454 2015-06-27 19:43
    关注

    I think you may need to set the User-Agent header in your JSON request. Try adding a line in JSONParser file where you making HttpRequest() before the call to execute() like:

    httpPost.setHeader('User-Agent','Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36');
    

    I faced the same problem.. This solution was given by @morphatic and it worked perfectly in my case.. DO vote him up.. JSON is showing error 403 while trying to fetch data from database in android

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 maixpy训练模型,模型训练好了以后,开发板通电会报错,不知道是什么问题
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题