mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-12 22:38:49 +00:00
handle HASESSIONID cookie
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@668 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
1cf6a3e0e0
commit
179675506d
4 changed files with 32 additions and 10 deletions
|
@ -92,9 +92,7 @@ public final class ParserUtils
|
|||
connection.addRequestProperty("Cache-Control", "no-cache");
|
||||
|
||||
if (cookieHandling && stateCookie != null)
|
||||
{
|
||||
connection.addRequestProperty("Cookie", stateCookie);
|
||||
}
|
||||
|
||||
if (request != null)
|
||||
{
|
||||
|
@ -124,7 +122,7 @@ public final class ParserUtils
|
|||
{
|
||||
for (final String value : entry.getValue())
|
||||
{
|
||||
if (value.startsWith("NSC_"))
|
||||
if (value.startsWith("NSC_") || value.startsWith("HASESSIONID"))
|
||||
{
|
||||
stateCookie = value.split(";", 2)[0];
|
||||
}
|
||||
|
@ -169,10 +167,11 @@ public final class ParserUtils
|
|||
|
||||
public static final InputStream scrapeInputStream(final String url) throws IOException
|
||||
{
|
||||
return scrapeInputStream(url, null, 3);
|
||||
return scrapeInputStream(url, null, false, 3);
|
||||
}
|
||||
|
||||
public static final InputStream scrapeInputStream(final String url, final String postRequest, int tries) throws IOException
|
||||
public static final InputStream scrapeInputStream(final String url, final String postRequest, final boolean cookieHandling, int tries)
|
||||
throws IOException
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
|
@ -187,6 +186,9 @@ public final class ParserUtils
|
|||
// workaround to disable Vodafone compression
|
||||
connection.addRequestProperty("Cache-Control", "no-cache");
|
||||
|
||||
if (cookieHandling && stateCookie != null)
|
||||
connection.addRequestProperty("Cookie", stateCookie);
|
||||
|
||||
if (postRequest != null)
|
||||
{
|
||||
connection.setRequestMethod("POST");
|
||||
|
@ -204,6 +206,24 @@ public final class ParserUtils
|
|||
final String contentEncoding = connection.getContentEncoding();
|
||||
final InputStream is = connection.getInputStream();
|
||||
|
||||
if (cookieHandling)
|
||||
{
|
||||
for (final Map.Entry<String, List<String>> entry : connection.getHeaderFields().entrySet())
|
||||
{
|
||||
if ("set-cookie".equalsIgnoreCase(entry.getKey()))
|
||||
{
|
||||
for (final String value : entry.getValue())
|
||||
{
|
||||
if (value.startsWith("NSC_") || value.startsWith("HASESSIONID"))
|
||||
{
|
||||
stateCookie = value.split(";", 2)[0];
|
||||
System.out.println(stateCookie);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ("gzip".equalsIgnoreCase(contentEncoding))
|
||||
return new GZIPInputStream(is);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue