Can someone show the translation from .NET to classic ASP , either Javascript or VBscript
for this code that logins in, sets a cookie, then and gets a PDF from a remote web server? Thanks in advance.
GetPdf(string page_link, string filename)
{
string username = "myusername";
string pass = "mypassword";
string codePageName = "UTF-8";
string loginPostData = "userName=" + username + "&Password=" + pass;
HttpWebRequest httpRequest = WebRequest.Create("
http://sitename/auth.aspx") as HttpWebRequest;
httpRequest.AllowAutoRedir
ect = false;
httpRequest.Method = "POST";
httpRequest.ContentType = "application/x-www-form-ur
lencoded";
Encoding enc = Encoding.GetEncoding(codeP
ageName);
byte[] bytes = enc.GetBytes(loginPostData
);
httpRequest.ContentLength = bytes.Length;
Stream reqStream = httpRequest.GetRequestStre
am();
reqStream.Write(bytes, 0, bytes.Length);
reqStream.Flush();
HttpWebResponse response = httpRequest.GetResponse() as HttpWebResponse;
string cookie = response.Headers["Set-Cook
ie"];
WebClient webclient = new WebClient();
webclient.Headers.Add("Coo
kie", " " + cookie.Replace("HttpOnly,"
, "HttpOnly; "));
webclient.DownloadFile(pag
elink, filename);
Response.ContentType = "application/pdf";
Response.Clear();
Response.TransmitFile(file
name);
Response.End();
}
Open in new window
Let us know how you make out, and if you have any issues with it...