简体   繁体   中英

classic asp page httprequest on aspx page?

I am having trouble finding a way to use httprequest in classic to pull data from an aspx that is also calling a reqeust.

classic code:

    HostURL = "https://URL"
    NetURL = "middle.aspx?HostURL=" & HostUR

    Dim oXMLHTTP
    Dim strStatusTest

    Set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")

    oXMLHTTP.Open "POST", NetURL, False
    oXMLHTTP.Send
    strStatusText = oXMLHTTP.responseText 

the netURL aspx code

private void Page_Load(object sender, System.EventArgs e){
    String host = getParam();
       HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(host);
        HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();

    String cc;
        using (Stream stream = response.GetResponseStream())
       {
          StreamReader reader = new StreamReader(stream, Encoding.UTF8);
          cc = reader.ReadToEnd();
       }       
    Response.Write(cc);
}

so what im attempting to do is when i call the aspx page from classic, the aspx on load gets a key that I need the asp page to have.

the aspx code works fine, it does retrieve the key that I need.

additional info: we turned off TLS 1.0 and manager does not want to do the registry fix. I am also a very junior programmer so this might not even work, I don't know.

Thank you in advance for any and all help.

There are a few issues with your code

As JohnRC's comment points out - https://URL is suspect. I assume though that you've substituted this for an actual URL which you don't want to display on this forum.

NetURL needs to be an absolute URL, ie

NetURL = "http://www.yourdomain.com/middle.aspx?HostURL=" & HostURL

Also, in the code you've provided you've left the "L" off the end of HostURL in the second line, if this is in your actual code then obviously the variable won't be passed to your aspx page.

Finally, it's not an error, but I recommend using MSXML2.ServerXMLHTTP.6.0 rather than 3.0 - it calls the most recent version of MSXML

I am making no comment on why and why not to do this... but I have a good use case. I wrote a library, and since then 100's of Classic ASP pages (in 1998 to 2005) to use it. This library handles and wraps the FileSystemObject. But in the newer OS's I have been getting lots of issues with mappings . So I decided to start using the ASPX version of this library (used in a lot of ASPX's :-). So I turn the ASPX library into a POST webservice by adding a "on this request do this function" code in the lib's main. Then I rewrote the FSO.inc to use ServerXMLHTTP to call the FSO.ASPX, with the requests to write/read/delete/whatever the files. So far, no problems... In the ASPX, below my public shared global class FSO:

<%
Select Case UCase(Current.Request("f"))
Case "READALL":     Response.write( FSO.ReadAll(Current.Request("filename")) )
Case "FILEEXISTS":  Response.write( FSO.FileExists(Current.Request("filename")) )
End select
%>

and then in the FSO.inc:

function CallFSO(exec)
    Dim objSrvHTTP
    Set objSrvHTTP = Server.CreateObject ("MSXML2.ServerXMLHTTP")
    objSrvHTTP.SetProxy 1
    objSrvHTTP.open "POST", "http://.......your server..../FSO.aspx", False
    objSrvHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    objSrvHTTP.send exec
    IF objSrvHTTP.status = 200 Then CallFSO = objSrvHTTP.responseText
    Set objSrvHTTP = nothing
End function

FUNCTION ReadAll(Filename)
    ReadAll = CallFSO( "f=readAll&FileName=" & filename)
End function

Function FileExists(Filename)
    FileExists = instr(CallFSO( "f=FileExists&FileName=" & filename), "True") > 0
End Function

Maybe not the most sufficient solution, but if you have a truck load of ASPs, and no resources to rewrite it, this works...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM