当我尝试从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.
我有一个名为query3.php的php脚本,它返回来自Android游戏的最大标点符号,存储在mysql数据库中 。 p>
直到今天它仍然运行良好,但现在它返回Access denied err403。 我没有对代码进行任何更改。 p>
奇怪的是,如果我在浏览器中输入网址,它可以正常工作,我会看到JSON编码的数据。 只有当我从Android应用程序访问时才会出现此问题。 p>
在数据库的Access日志中,它显示如下: p>
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)”
code> pre>
它们可能是在服务器中配置的新东西? 我写信给他们但还没有得到答复。 p>
div>
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