0

I have made a call to a .NET DLL (class library project) using XmlHttpRequest:

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;
}

How could I retrieve the parameters at server side that are sent using .send() method of the above request?

Additional Information:
Basically in the Sage CRM it calls a DLL (eware.dll) in the browser to render output for Sage CRM pages. And if we want to call our custom server side assembly we have to provide DLL name and method name in query string like this: http://localhost/installname/eware.dll?SID=xxxxx&Act=123&dotnetdll=dllname&dotnetfunc=m‌​ethodname. So the question is in this scenario.

Later I found the way to retrieve the querystring parameter on the server side (library project/DLL) using Sage CRM .NET API, however still wandering if we could have been able to retrieve the xmlHttpRequest.send() parameters in the server side library porject (DLL)?

Khadim Ali
  • 2,548
  • 3
  • 33
  • 61
  • And how would you do it for a normal POST request? – epascarello Jul 14 '14 at 02:07
  • well, usually I have used querystring to pass parameters to an `asp.net` page that could be retrieved using `Request.QueryString()` on server side. But the resource being called is not an asp.net page here. – Khadim Ali Jul 14 '14 at 02:12
  • 1
    [Pssst...](http://stackoverflow.com/questions/976613/get-post-data-in-c-asp-net). Also, I like how you have named the function `httpGet` when it actually performs a _POST_. – sampathsris Jul 14 '14 at 02:44
  • "call to a .NET DLL"??? Are you using ASP.Net/ASP.Net MVC or some custom web server? – Alexei Levenkov Jul 14 '14 at 03:24
  • @Krumia that was a typo. well I read your link but it is related to asp.net. However, I tried adding System.Web namespace to my class library project. But it is returning `null in System.Web.HttpContext.Current` – Khadim Ali Jul 14 '14 at 07:38
  • @AlexeiLevenkov Yes it is class library project (DLL) that is being called via a third party DLL in the browser. If those details matter, I may post them. – Khadim Ali Jul 14 '14 at 07:40
  • I'm at loss how these two statements can go together: "retrieve the parameters at server side" and "library project (DLL) that is being called via a third party DLL in the browser". If you have question on how to handle request on server consider specifying what server side stack you use. – Alexei Levenkov Jul 14 '14 at 14:24
  • @Ali.NET: Please refrain from adding more than 1 question to a question. If you have a separate question, as it as a separate question. – Matt Jul 15 '14 at 21:02
  • @Matt well, it was not another question. It was just the technical side of the question or better to say a technical hint for finding the possible solution. – Khadim Ali Jul 16 '14 at 10:09
  • @AlexeiLevenkov basically in Sage CRM it calls a DLL (eware.dll) in the browser to render output for Sage CRM pages. And if we want to call our custom server side code we have to provide DLL and method name in query string. Like this: `http://localhost/installname/eware.dll?SID=xxxxx&dotnetdll=dllname&dotnetfunc=methodname`. So this question in this scenario. – Khadim Ali Jul 17 '14 at 01:28
  • @AlexeiLevenkov However later I have found the way to retrieve the querystring parameter on the server side (library project/DLL) using Sage CRM .NET API but still wandering if we can retrieve the xmlHttpRequest.send() parameters in the server side library porject (DLL)? – Khadim Ali Jul 17 '14 at 01:31
  • I have no idea what "Sage CRM" is so I can't help you. It would be good idea to provide information you have in comments in your question when you've asked it.... – Alexei Levenkov Jul 17 '14 at 04:40

1 Answers1

1

I made the what you want in the following way:

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;

And in the server side:

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

Hope it helps you.

  • Yeah, i also found the way to retrieve query string parameters on server. See the last para in my original post. However data sent through.send() method was still inaccessible. – Khadim Ali May 18 '18 at 01:02