Changing User Agent in OSMDroid

被刻印的时光 ゝ 提交于 2020-01-03 02:56:08

问题


Is it possible to change User Agent I send with every tile request in OSMDroid?

I'm currently getting 403 Forbidden error whenever I try to download a tile (as described in another SO question), probably because OSMDroid itself has been banned.


回答1:


Please follow Issue 515 to track this issue. We have implemented a fix and we will release a proper update soon. We will be providing a factory interface for customizing the user-agent.




回答2:


It looks like the only way to specify the User Agent is to modify OSMDroid's MapTileDownloader.loadTile() method in the following way:

final HttpClient client = new DefaultHttpClient();
final HttpUriRequest head = new HttpGet(tileURLString);
head.setHeader("User-Agent", "OSMDroid"); // Add this line
final HttpResponse response = client.execute(head);

It solves the 403 Forbidden tile download problem.




回答3:


I had the same problem and I just downloaded the following jar file

https://oss.sonatype.org/content/groups/public/org/osmdroid/osmdroid-android/4.1/osmdroid-android-4.1.jar

It's the osmdroid-android-4.1.jar , put it in your /Libs project folder.



来源:https://stackoverflow.com/questions/21217781/changing-user-agent-in-osmdroid

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