hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christophe Marchand <christophe.march...@axyus.com>
Subject Re: Download a file by going to website and submitting a form
Date Mon, 03 May 2010 10:01:29 GMT
Or contact the web-site administrator and ask him the detail URL API 
(i.e. the exact content required in each parameter).

Regards,
Christophe

sebb wrote:
> On 30/04/2010, Mini Traktor <minitraktor@yahoo.com> wrote:
>   
>> Hi!
>>
>>  I used Proxomitron to find out that the parameters were being posted when clicking
on the download button (the "SÖK" button):
>>
>>  __VIEWSTATE=%2FwEPDwUJMTMxNTMwMTE1D2QWAmYPZBYCAgMPZBYEAgEPZBYkAgMPPCsADQEMFCsABQ
>>      UPMDowLDA6MSwwOjIsMDozFCsAAhYEHgRUZXh0BQVCb2xhZx4ISW1hZ2VVcmwFLH4vUGFnZVRlbX
>>      BsYXRlcy9pbWFnZXMvRklfR3JlZW4tZG90LTEwcHgucG5nZBQrAAIWAh8ABQxJbnN5bnNwZXJzb2
>>      5kFCsAAhYCHwAFBURhdHVtZBQrAAIWAh8ABRhSZWdpc3RyZXJhZCBpbnN5bnNoYW5kZWxkZAIFDw
>>      8WAh8ABRVURUxJQVNPTkVSQSBBQiAoUFVCTClkZAIHDxAPFgQfAAUORXhwb3J0ZXJhIGRhdGEeB0
>>      NoZWNrZWRnZGRkZAIJDw8WAh8ABRRPcmdhbmlzYXRpb25zbnVtbWVyOmRkAgsPDxYCHwAFCzU1Nj
>>      EwMy00MjQ5ZGQCDQ8PFgIfAAUXUmVnaXN0cmVyaW5nIHVwcGjDtnJ0OiBkZAIPDxAPFgQfAmgfAA
>>      UPVmlzYSBww6Ugc2vDpHJtZGRkZAIRDw8WAh8ABQVWw6RsamRkAhMPEGQQFQUNVHJhbnNha3Rpb2
>>      5lchBBa3R1ZWxsdCBpbm5laGF2Ekhpc3Rvcmlza3QgaW5uZWhhdgVJbnN5bhlCZWZhdHRuaW5nc2
>>      bDtnLDpG5kcmluZ2FyFQUNVHJhbnNha3Rpb25lcgdJbm5laGF2EUhpc3Rvcmlza3RJbm5laGF2BU
>>      luc3luGUJlZmF0dG5pbmdzZsO2csOkbmRyaW5nYXIUKwMFZ2dnZ2cWAQICZAIVDw8WBB8ABQZGci
>>      BvIG0eB1Zpc2libGVoZGQCFw8PFgQfAAUKMjAxMC0wNC0yOR8DaGRkAhkPDxYCHwAFBURhdHVtZG
>>      QCGw8PFgIfAAUKMjAwOS0wNC0zMGRkAh0PDxYCHwNoZGQCHw8PFgIfAQUofi9QYWdlVGVtcGxhdG
>>      VzL2ltYWdlcy9idXR0b25fc2VhcmNoLmdpZmRkAiEPDxYCHwAFDUbDtnJrbGFyaW5nYXJkZAIlDw
>>      8WAh8ABQM1NTZkZAInDw8WAh8ABQVEYXR1bWRkAgIPDxYCHwAFEFRmbiAwOC03ODcgODEgNDRkZB
>>      gCBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WBAUUY3RsMDAkbWFpbiRvcHRFeHBvcn
>>      QFFGN0bDAwJG1haW4kb3B0U2NyZWVuBRRjdGwwMCRtYWluJG9wdFNjcmVlbgUXY3RsMDAkbWFpbi
>>      RJbWFnZUJ1dHRvbjEFFGN0bDAwJG1haW4kR3JpZFZpZXcxD2dkplQcCA16XUJKgpVj4bTiEdM5Yb
>>      Q%3D
>>  ctl00%24main%24ResultFormatGroup=optExport
>>  ctl00%24main%24DropDownList1=HistorisktInnehav
>>  ctl00%24main%24tomDate=2009-04-30
>>  ctl00%24main%24ImageButton1.x=13
>>  ctl00%24main%24ImageButton1.y=15
>>  __EVENTVALIDATION=%2FwEWDwLizLyxCgLupZC3DALVvMvkCALOkpvRAwLuqaGYAgLghIvcCQL%2Fl4qFBQLYqZBBAoqhrtUDAqGXz60BAret0%2FoPArax8coKAoX27r0IAtmB4skKAv2novYCatM9TQQ4OL1ojfRmfYIduKKQ%2Fwc%3D
>>
>>  However, posting the same parameters from HttpClient gives the following response:
>>
>>  "<html><head><title>Object moved</title></head><body>
>>  <h2>Object moved to <a href="/PageTemplates/errorNoSess.aspx?aspxerrorpath=/SearchPage.aspx">here</a>.</h2>
>>  </body></html>"
>>
>>  What can be the problem? I suppose it lies with the __VIEWSTATE and __EVENTVALIDATION
parameters as the values for these seems a bit... strange.
>>
>>     
>
> These values are likely to vary between requests, so you will have to
> extract them from the previous response.
>
>   
>>  Best regards,
>>  Mini
>>
>>
>>
>>  ________________________________
>>  From: Christophe Marchand <christophe.marchand@axyus.com>
>>  To: HttpClient User Discussion <httpclient-users@hc.apache.org>
>>  Sent: Fri, April 30, 2010 1:47:12 PM
>>  Subject: Re: Download a file by going to website and submitting a form
>>
>>
>>  Put a local proxy that log requests and watch out the parameters that are submitted
to server.
>>  Then you will just have to change your parameters values as you need.
>>
>>  Under windows (sometime...), I use Proxomitron
>>
>>  Regards,
>>  Christophe
>>
>>  Mini Traktor wrote:
>>  > Hi!
>>  >
>>  > I need to download a file using HttpClient. There is no URL that leads directly
to the file but it can be downloaded manually by following these steps:
>>  >
>>  > 1. Go to this website:
>>  > http://insynsok.fi.se/SearchPage.aspx?bolagid=556&fromdate=2009-04-30&tomdate=2009-04-30&reporttype=2&culture=sv-SE
>>  > 2. Select the radio button "Exportera data" in the top-right corner
>>  > 3. Click the button "SÖK"
>>  >
>>  > I suppose that I should do some kind of HTTP POST, but I don't know which parameters
to post. I have tried many different combinations, such as the one below. Do anyone know what
I should do to download the file?
>>  >    DefaultHttpClient httpclient =    HttpPost httpost =    List <NameValuePair>
nvps =    nvps.add(
>>  >    nvps.add(publicstaticvoidmain(String[] args) throwsException {newDefaultHttpClient();newHttpPost("http://insynsok.fi.se/SearchPage.aspx?bolagid=556&fromdate=2009-04-30&tomdate=2009-04-30&reporttype=2&culture=sv-SE");newArrayList
<NameValuePair>();newBasicNameValuePair("ctl00$main$ResultFormatGroup", "optExport"));newBasicNameValuePair("__EVENTTARGET",
"ctl00$main$optExport"));    // nvps.add(new BasicNameValuePair("__EVENTTARGET", "optExport"));
>>  >    // nvps.add(new B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xYCHwNoZGQCHw8PFgIfAQUofi9QY
>>  > WdlVGVtcGxhdGVzL2ltYWdlcy9idXR0b25fc2VhcmNoLmdpZmRkAiEPDxYCHwAFDUbDtnJrbGFyaW5nYXJkZAIlDw8WAh8ABQM1NTZkZAInDw8WAh8ABQVEYXR1bWRkAgIPDxYCHwAFEFRmbiAwOC03ODcgODEgNDRkZBgCBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WBAUUY3RsMDAkbWFpbiRvcHRFeHBvcnQFFGN0bDAwJG1haW4kb3B0RXhwb3J0BRRjdGwwMCRtYWluJG9wdFNjcmVlbgUXY3RsMDAkbWFpbiRJbWFnZUJ1dHRvbjEFFGN0bDAwJG1haW4kR3JpZFZpZXcxD2dkklF4trRBFw6yMlWuT6mgCtqFIVs="));
>>  >    // nvps.add(new BasicNameValuePair("ctl00$main$ResultFormatGroup", "optExport"));
>>  >    // nvps.add(new BasicNameValuePair("ctl00$main$DropDownList1", "HistorisktInnehav"));
>>  >    // nvps.add(new BasicNameValuePair("ctl00$main$tomDate", "2009-04-30"));
>>  >    // nvps.add(new BasicNameValuePair("__EVENTVALIDATION", "/wEWDwLHzJQpAu6lkLcMAtW8y+QIAs6Sm9EDAu6poZgCAuCEi9wJAv+XioUFAtipkEECiqGu1QMCoZfPrQECt63T+g8CtrHxygoChfbuvQgC2YHiyQoC/aei9gKbrpw0ozpPrgzd2imI6M4O/LNqOw=="));
>>  >    // nvps.add(new BasicNameValuePair("ctl00$main$ImageButton1", "true"));
   httpost.setEntity(
>>  >    HttpResponse response = httpclient.execute(httpost);
>>  >    HttpEntity entity = response.getEntity();    File file =    InputStream
instream = entity.getContent();
>>  >    OutputStream outstream =        outstream.write(tmp, 0, l);
>>  >    }
>>  >    outstream.flush();
>>  >    instream.close();
>>  >    outstream.close();
>>  >    entity.consumeContent();
>>  >    httpclient.getConnectionManager().shutdown(); }newUrlEncodedFormEntity(nvps,
HTTP.UTF_8));newFile("somefile.zip");newFileOutputStream(file);    byte[] tmp = newbyte[4096];
   intl;    while((l = instream.read(tmp)) != -1) {
>>  >
>>  >
>>  >
>>
>>
>>
>>
>>  ---------------------------------------------------------------------
>>
>> To unsubscribe, e-mail: mailto:httpclient-users-unsubscribe@hc.apache.org
>>  For additional commands, e-mail: mailto:httpclient-users-help@hc.apache.org
>>
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>
>   


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message