简体   繁体   English

aspx页面上的经典asp页面httprequest?

[英]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.我无法找到一种在经典中使用 httprequest 从也调用 reqeust 的 aspx 中提取数据的方法。

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 netURL aspx 代码

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.所以我试图做的是当我从经典调用 aspx 页面时,加载时的 aspx 获取我需要 asp 页面具有的键。

the aspx code works fine, it does retrieve the key that I need. aspx 代码工作正常,它确实检索了我需要的密钥。

additional info: we turned off TLS 1.0 and manager does not want to do the registry fix.附加信息:我们关闭了 TLS 1.0 并且经理不想进行注册表修复。 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.正如 JohnRC 的评论指出的那样 - https://URL是可疑的。 I assume though that you've substituted this for an actual URL which you don't want to display on this forum.我假设您已将其替换为您不想在此论坛上显示的实际 URL。

NetURL needs to be an absolute URL, ie NetURL 需要是绝对 URL,即

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.此外,在您提供的代码中,您在第二行的HostURL末尾留下了“L”,如果这是在您的实际代码中,那么显然该变量不会传递到您的 aspx 页面。

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最后,这不是错误,但我建议使用MSXML2.ServerXMLHTTP.6.0而不是 3.0 - 它调用最新版本的 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.我写了一个库,从那时起有 100 个经典 ASP 页面(在 1998 年到 2005 年)使用它。 This library handles and wraps the FileSystemObject.该库处理和包装 FileSystemObject。 But in the newer OS's I have been getting lots of issues with mappings .但是在较新的操作系统中,我遇到了很多mappings问题。 So I decided to start using the ASPX version of this library (used in a lot of ASPX's :-).所以我决定开始使用这个库的 ASPX 版本(在很多 ASPX 中使用:-)。 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.因此,我通过在 lib 的 main.js 中添加“在此请求上执行此功能”代码将 ASPX 库转换为 POST Web 服务。 Then I rewrote the FSO.inc to use ServerXMLHTTP to call the FSO.ASPX, with the requests to write/read/delete/whatever the files.然后我重写了 FSO.inc 以使用 ServerXMLHTTP 调用 FSO.ASPX,请求写入/读取/删除/任何文件。 So far, no problems... In the ASPX, below my public shared global class FSO:到目前为止,没有问题......在 ASPX 中,在我的公共共享全局类 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:然后在 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...也许不是最充分的解决方案,但是如果您有一卡车的 ASP,并且没有资源来重写它,那么这可行...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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