Solved

C# to  ASP   translation

Posted on 2013-11-25
4
454 Views
Last Modified: 2013-12-10
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.AllowAutoRedirect = false;
        httpRequest.Method = "POST";
        httpRequest.ContentType = "application/x-www-form-urlencoded";

        Encoding enc = Encoding.GetEncoding(codePageName);
        byte[] bytes = enc.GetBytes(loginPostData);
        httpRequest.ContentLength = bytes.Length;
        Stream reqStream = httpRequest.GetRequestStream();
        reqStream.Write(bytes, 0, bytes.Length);
        reqStream.Flush();

        HttpWebResponse response = httpRequest.GetResponse() as HttpWebResponse;
        string cookie = response.Headers["Set-Cookie"];

        WebClient webclient = new WebClient();
        webclient.Headers.Add("Cookie", " " + cookie.Replace("HttpOnly,", "HttpOnly; "));
        webclient.DownloadFile(pagelink, filename);
       
        Response.ContentType = "application/pdf";
        Response.Clear();
        Response.TransmitFile(filename);
        Response.End();
}
0
Comment
Question by:awalkinthepark
  • 2
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
kevp75 earned 500 total points
ID: 39677558
Modify to suit your needs, but we won't help unless you try to do it yourself...

public function SaveFileFromUrl(Url, FileName)
    dim objXMLHTTP, objADOStream, objFSO

    Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.3.0")

    objXMLHTTP.open "GET", Url, false
    objXMLHTTP.send()

    If objXMLHTTP.Status = 200 Then 
        Set objADOStream = CreateObject("ADODB.Stream")
        objADOStream.Open
        objADOStream.Type = 1 'adTypeBinary

        objADOStream.Write objXMLHTTP.ResponseBody
        objADOStream.Position = 0 'Set the stream position to the start

        Set objFSO = Createobject("Scripting.FileSystemObject")
        If objFSO.Fileexists(FileName) Then objFSO.DeleteFile FileName
        Set objFSO = Nothing

        objADOStream.SaveToFile FileName
        objADOStream.Close
        Set objADOStream = Nothing

        SaveFileFromUrl = objXMLHTTP.getResponseHeader("Content-Type")
    else
        SaveFileFromUrl = ""
    End if

    Set objXMLHTTP = Nothing
end function

Open in new window


Let us know how you make out, and if you have any issues with it...
0
 

Author Comment

by:awalkinthepark
ID: 39678462
Sure, wasn't expecting anything more than the fundamental pieces.
Appreciate the help.
0
 
LVL 25

Expert Comment

by:kevp75
ID: 39678562
That should definately get you going.
0
 

Author Closing Comment

by:awalkinthepark
ID: 39709623
Thanks - can work with this.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Replacing HTML tags in Textarea/Textbox 5 47
Asp.net mvc entity issue 6 31
Get Reply from SSIS to intranet site when finished 3 33
Remove greater than sign 3 43
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now