Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C# to  ASP   translation

Posted on 2013-11-25
4
Medium Priority
?
479 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

650 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