Solved

C# to  ASP   translation

Posted on 2013-11-25
4
464 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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 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