mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-13 08:10:46 +00:00
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:
parent
06712bf0eb
commit
b990d82f8e
2 changed files with 78 additions and 1 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue