hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mini Traktor <minitrak...@yahoo.com>
Subject Download a file by going to website and submitting a form
Date Fri, 30 Apr 2010 11:37:27 GMT
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 BasicNameValuePair("__LASTFOCUS", ""))
    // nvps.add(new BasicNameValuePair("__EVENTARGUMENT", ""));
    // nvps.add(new BasicNameValuePair("__VIEWSTATE",
 "/wEPDwUJMTMxNTMwMTE1D2QWAmYPZBYCAgMPZBYEAgEPZBYkAgMPPCsADQEMFCsABQUPMDowLDA6MSwwOjIsMDozFCsAAhYEHgRUZXh0BQVCb2xhZx4ISW1hZ2VVcmwFLH4vUGFnZVRlbXBsYXRlcy9pbWFnZXMvRklfR3JlZW4tZG90LTEwcHgucG5nZBQrAAIWAh8ABQxJbnN5bnNwZXJzb25kFCsAAhYCHwAFBURhdHVtZBQrAAIWAh8ABRhSZWdpc3RyZXJhZCBpbnN5bnNoYW5kZWxkZAIFDw8WAh8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yMlWuT6mgCtqFIVs="));
    // 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) {


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