autocomplete using XML-interface for Switzerland and Belgium (forgot)

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@301 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach 2010-10-16 22:16:36 +00:00
parent 06712bf0eb
commit b990d82f8e
2 changed files with 78 additions and 1 deletions

View file

@ -164,17 +164,33 @@ public final class ParserUtils
}
public static final InputStream scrapeInputStream(final String url) throws IOException
{
return scrapeInputStream(url, null);
}
public static final InputStream scrapeInputStream(final String url, final String postRequest) throws IOException
{
final HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setDoInput(true);
connection.setDoOutput(false);
connection.setDoOutput(postRequest != null);
connection.setConnectTimeout(SCRAPE_CONNECT_TIMEOUT);
connection.setReadTimeout(SCRAPE_READ_TIMEOUT);
connection.addRequestProperty("User-Agent", SCRAPE_USER_AGENT);
// workaround to disable Vodafone compression
connection.addRequestProperty("Cache-Control", "no-cache");
if (postRequest != null)
{
connection.setRequestMethod("POST");
connection.addRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.addRequestProperty("Content-Length", Integer.toString(postRequest.length()));
final Writer writer = new OutputStreamWriter(connection.getOutputStream(), SCRAPE_DEFAULT_ENCODING);
writer.write(postRequest);
writer.close();
}
return connection.getInputStream();
}