Java post request to Overpass API

Hello,

can someone help me with the source code for a java xml post request to Overpass API Interpreter?

I mean the equivalent code in java for this python sequence:

import requests
r = requests.post(‘http://overpass-api.de/api/interpreter’,
data=open(‘Bethesda.xml’, ‘rb’))
print(r.text)

Thank you!

Hi Simona,

this shouldn’t be too hard to figure out, you will find plenty of examples if you google “java post request”. Please be more specific and post some Java code if you are still having problems!

Paul

I solved the issue. Thanks!

For the benefit of everyone who arrives at this thread with the same problem in the future, it would be helpful if you posted how you solved it.

HttpClient client = new DefaultHttpClient();

	HttpPost post = new HttpPost(
			"[http://overpass-api.de/api/interpreter](http://overpass-api.de/api/interpreter)");

	String xmlString = "....";

	System.out.println(xmlString);

	try {

		HttpEntity entity = new ByteArrayEntity(xmlString
				.getBytes("UTF-8"));

		post.setEntity(entity);

		HttpResponse response = client.execute(post);

		String resultString = EntityUtils.toString(response
				.getEntity());

		System.out.println(resultString);

	} catch (Exception ex) {
		ex.printStackTrace();

	}

I mention that I changed the way to send the request to the interpeter. I used a xmlString instead of a xml file.