Add user-agent

This commit is contained in:
Victor Shcherb 2013-05-20 10:56:24 +02:00
parent af8d3db5b5
commit 0028c3a11d
4 changed files with 12 additions and 2 deletions

View file

@ -74,7 +74,7 @@ public class LocalOpenstreetmapActivity extends OsmandListActivity {
dbbug = new OsmBugsDbHelper(this);
remotepoi = new OpenstreetmapRemoteUtil(this, this.getWindow().getDecorView());
remotebug = new OsmBugsRemoteUtil();
remotebug = new OsmBugsRemoteUtil(getMyApplication());
}

View file

@ -184,6 +184,7 @@ public class OpenstreetmapRemoteUtil extends AbstractOpenstreetmapUtil {
connection.setConnectTimeout(15000);
connection.setRequestMethod(requestMethod);
connection.setRequestProperty("User-Agent", Version.getFullVersion(ctx)); //$NON-NLS-1$
StringBuilder responseBody = new StringBuilder();
if (doAuthenticate) {
String token = settings.USER_NAME.get() + ":" + settings.USER_PASSWORD.get(); //$NON-NLS-1$

View file

@ -87,7 +87,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
public OsmBugsLayer(MapActivity activity){
this.activity = activity;
local = new OsmBugsLocalUtil(activity);
remote = new OsmBugsRemoteUtil();
remote = new OsmBugsRemoteUtil(activity.getMyApplication());
}
public OsmBugsUtil getOsmbugsUtil(OpenStreetBug bug) {

View file

@ -8,6 +8,8 @@ import java.net.URLConnection;
import java.net.URLEncoder;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.Version;
import org.apache.commons.logging.Log;
@ -17,6 +19,12 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil {
private final static String SITE_API = "http://openstreetbugs.schokokeks.org/api/0.1/"; //$NON-NLS-1$
private OsmandApplication app;
public OsmBugsRemoteUtil(OsmandApplication app) {
this.app = app;
}
@Override
public boolean createNewBug(double latitude, double longitude, String text, String authorName){
StringBuilder b = new StringBuilder();
@ -58,6 +66,7 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil {
log.debug("Action " + debugAction + " " + urlStr); //$NON-NLS-1$ //$NON-NLS-2$
URL url = new URL(urlStr);
URLConnection connection = url.openConnection();
connection.setRequestProperty("User-Agent", Version.getFullVersion(app)); //$NON-NLS-1$
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while(reader.readLine() != null){
}