?
Solved

C# to  ASP   translation

Posted on 2013-11-25
4
Medium Priority
?
478 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
kevp75 earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

764 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