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

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

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?