0
Reply

Https SSL login and PDF download

Matteo Alvisi

Matteo Alvisi

Apr 22 2012 3:43 AM
3.6k
Hi guys, I am writing for help for this problem: connect to the site of one of our suppliers and automatically download invoices in PDF. I tried several ways:
1: Webbrowser -  I can get to the page with links to the pdf but I can not save them to disk (opens in new window) (PDF's are generated on the fly and are of this type https://www.axxes.fr/it/client/pge1_relevefacturepdf.aspx?selnumdoc=700051126&typ=DUP&lng=ES&famdoc=DUP&typfic=PDF)
2: Watin - I can not save automatically the pdf like Webbrowser
3: HttpWebRequest - I can not login. This is the code I use:

string post_data = "_cm_url=/it/client/default.aspx&_cm_user=user&_cm_pwd=pwd";
string uri = "https://www.axxes.fr/it/identification/default.cgi";
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(uri); request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.Method = "POST";
byte[] postBytes = Encoding.ASCII.GetBytes(post_data);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postBytes.Length;
System.Net.ServicePointManager.CertificatePolicy= new MyPolicy();
Stream requestStream = request.GetRequestStream();
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
listBox1.Text=(new StreamReader(response.GetResponseStream()).ReadToEnd());
Console.WriteLine(response.StatusCode);
}
public class MyPolicy : ICertificatePolicy
{
public bool CheckValidationResult(ServicePoint srvPoint,
X509Certificate certificate, WebRequest request,
int certificateProblem)
{
return true;
}
}


The supplier site is https://www.axxes.fr/it/
The authentication module is this:
<form name="blocident" action="/it/identification/default.cgi
" method="POST"> <input type="hidden" name="_cm_url" value="/it/client/default.aspx"> <div class="e_idlign"> <div class="e_idcol1"> <label for="login" accesskey="2">Login</label> <input type="text" class="e_chp77px" name="_cm_user" id="login"> </div> <div class="nof"></div> <div class="e_idcol2"> <label for="password">Password</label> <input type="password" class="e_chp77px" name="_cm_pwd" id="password"> </div> </div> <div class="e_idlign"> <input type="image" alt="Valider l'identification" src="/it/images/css/env/bt_ok.gif" class="e_btOk" name="btOk"> </div> <ul id="e_identLien"> <li class="sep"><a href="/it/pge1_clientmoralcreation.aspx">Iscriversi</a></li> <li><a href="/it/pge1_question.aspx">Password dimenticata?</a></li> </ul> </form>

With Fiddler I tried to analyze the traffic of a navigation browser and this is because:

1
POST /it/identification/default.cgi HTTP/1.1
_cm_url=%2Fit%2Fclient%2Fdefault.aspx&_cm_user=u
ser&_cm_pwd=password&btOk.x=23&btOk.y=12

2
GET /it/client/default.aspx HTTP/1.1
ASP.NET_SessionId=3hbcfrzstvxwo145tpgpvmvw
IdSes=4fba1069405c428bab1........

3
GET /it/client/pge1_clientrecherche.aspx HTTP/1.1
ASP.NET_SessionId=3hbcfrzstvxwo145tpgpvmvw
IdSes=4fba1069405c428.............


While the code I posted is only a request to the CGI.
I honestly can not figure out how to access. Seems like something is missing .. the cookie? How to manage it? Do you have any tips?

Any idea?
Thanx again