【问题标题】:How to retrieve Http Request parameters on .NET server side如何在 .NET 服务器端检索 Http 请求参数
【发布时间】:2014-09-03 21:40:36
【问题描述】:

我已经使用 XmlHttpRequest 调用了一个 .NET DLL(类库项目):

function httpGet(theUrl, sendParam) {
    var xmlHttp = null;

    xmlHttp = new XMLHttpRequest();
    xmlHttp.open('POST', theUrl, false);
    xmlHttp.setRequestHeader('Content-Type', 'text/xml');
    xmlHttp.send(sendParam);
    var strHtml = xmlHttp.responseText;
    xmlHttp = null; // always clear the XmlHttp object when you are done to avoid memory leaks

    return strHtml;
}

如何在服务器端检索使用上述请求的 .send() 方法发送的参数?

其他信息:
基本上在 Sage CRM 中,它调用浏览器中的 DLL (eware.dll) 来呈现 Sage CRM 页面的输出。如果我们想调用我们的自定义服务器端程序集,我们必须在查询字符串中提供 DLL 名称和方法名称,如下所示:http://localhost/installname/eware.dll?SID=xxxxx&Act=123&dotnetdll=dllname&dotnetfunc=m‌​ethodname。所以问题就在这个场景中。

后来我找到了使用 Sage CRM .NET API 在服务器端(库项目/DLL)检索查询字符串参数的方法,但是如果我们能够在服务器端库项目(DLL)?

【问题讨论】:

  • 对于一个普通的 POST 请求你会怎么做?
  • 好吧,通常我使用查询字符串将参数传递给asp.net 页面,该页面可以在服务器端使用Request.QueryString() 检索。但是这里调用的资源不是asp.net页面。
  • Pssst...。另外,我喜欢你在实际执行 POST 时将函数命名为 httpGet
  • "调用 .NET DLL"???您使用的是 ASP.Net/ASP.Net MVC 还是一些自定义 Web 服务器?
  • @Krumia 这是一个错字。好吧,我阅读了您的链接,但它与 asp.net 有关。但是,我尝试将 System.Web 命名空间添加到我的类库项目中。但它正在返回null in System.Web.HttpContext.Current

标签: c# javascript .net dll xmlhttprequest


【解决方案1】:

我通过以下方式制作了您想要的东西:

var request = new XMLHttpRequest();
    request.responseType = "blob";

    request.open("GET", '/Reports/Report1?type=myParam');
    request.onload = function () {
        var url = window.URL.createObjectURL(this.response);
        var a = document.createElement("a");
        document.body.appendChild(a);
        a.href = url;
        a.download = this.response.name || "Mensajes" + $.now()
        a.click();
    }
    request.send();

    $scope.procesando = true;

    $scope.procesando = false;

在服务器端:

[HttpGet]
public FileStreamResult Report1()
{
    string tipo = Request.QueryString["type"];
    ...
    ...
    ...
}

希望对你有帮助。

【讨论】:

  • 是的,我还找到了在服务器上检索查询字符串参数的方法。请参阅我原始帖子中的最后一段。但是通过 .send() 方法发送的数据仍然无法访问。
猜你喜欢
  • 2018-08-09
  • 1970-01-01
  • 2018-02-15
  • 1970-01-01
  • 1970-01-01
  • 2012-04-18
  • 2020-03-04
  • 2013-09-30
  • 1970-01-01
相关资源
最近更新 更多