httpURLConnection with user-agent gets 403 Forbidden but not web browser

只谈情不闲聊 提交于 2019-12-24 10:35:55

问题


I'm running a program that sends requests to the public facebook graph API. Its multithreaded,and user-agent is set ("Mozilla/5.0...").

After 1000-10000 requests it starts getting exception:

"java.io.IOException: Server returned HTTP response code: 403 for URL = https://graph.facebook.com/etc..."

for all threads trying to get a response.
If i stop the process, and restart it, after lets say 10 minutes, it will work, but it will get the exceptions after less requests. While program is running, and getting these exceptions, I've checked the request via chrome web browser and it got the responses just fine.

I've tried switching user-agent strings on runtime, but it didn't work. Setting a global delay time to all threads when a single thread encounters the exception sometimes works, the timeout isn't consistent.

Since the ip isn't blocked, I'm having a hard time figuring how the API identifies my request and know that I'm not using an actual browser even with user agent property is defined.

来源:https://stackoverflow.com/questions/27604502/httpurlconnection-with-user-agent-gets-403-forbidden-but-not-web-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!