How to get web api request data (Get,Post,Put and Delete) from the raw request itself not receiving it in a method parameters - httprequest

I am using WorkContext that contains information about the current request such as logged-in user, current culture and so on;
My question is i want to Interrogates HttpContext.Current to get data from request;(Method Body; i already know how to get it from query string) i mean i want to get Jason Data that is passed when the user make the request in case of Get,Post,Put and Delete requests; note i want to get data from raw url HttpContext.Current.Request not receive data in a method paraemeter as i want to get generic data that is common on all methods

I think the property you want (assuming I understood your question) is HttpContext.Current.Request.RequestType. If you wanted Json you could do:
var rType = new { Method = HttpContext.Current.Request.RequestType };
var thing = JsonConvert.SerializeObject(rType);

Related

How to set http response code in Parse Server cloud function?

A parse server cloud function is defined via
Parse.Cloud.define("hello", function(request, response) {..});
on the response, I can call response.success(X) and response.error(Y), and that sets the http response code and the body of the response.
But how do I define a different code, like created (201)?
And how do I set the headers of the response?
thanks, Tim
You are allowed to return any valid JSON from response.success(). Therefore, you could create an object with fields such as code, message, and value, so you can set the code, give it a string descriptor, and pass back the value you normally would, if there is one. This seems to accomplish what you need, though you will have to keep track of those codes across your platforms. I recommend looking up standard http response codes and make sure you don't overlap with any standards.

Use Response of a wcf request as request in another receive port

Is there any way to use the response of a wcf service method request as an input for the next request in same orchestration and return the response of the first request as well as the response of the second request as out put in BizTalk?
Eg :
My first request gives a response as "a"
Give this response "a" as request to the 2nd request and gets the response as "b"
Return the response as "a" and "b".
Is this possible?
Yes. You could either create a map from Response 1 to Request 2, and also create a multiple input message map from Response 1 and Response 2 to your final output message.
If the messages involved don't have any repeating structures, it may be enough to distinguish the fields that you need to be concerned with and just use a ConstructMessage with an XmlDocument, i.e.
// construct shape code
varXmlDoc = new System.Xml.XmlDocument();
varXmlDoc.LoadXml("<webSvcRequest2 xmlns=''><ParamB>" + msgWebSvcResp1.ParamA + "</ParamB></webSvcRequest2>");
msgWebSvcReq2 = varXmlDoc;
And similar code for producing the final output message. If you go this route, I'd advice creating some C# utility methods to actually store the strings/message templates.

How to use SessionID using PostMan Rest client

Getting "SessionId" from response of user logged in session using POSTMAN REST client.
How to use the sessionId for other API calls of GET request?
Making a few assumptions about your data structure, store it as a variable:
//parse the response body as JSON
var data = JSON.parse(responseBody);
//create a global variable that can be reused in another call
postman.setGlobalVariable("sessionId", data.SessionId")
To use in a call to another endpoint:
http://www.example.com/{{sessionId}}

ASP.NET Web API - Reading querystring/formdata before each request

For reasons outlined here I need to review a set values from they querystring or formdata before each request (so I can perform some authentication). The keys are the same each time and should be present in each request, however they will be located in the querystring for GET requests, and in the formdata for POST and others
As this is for authentication purposes, this needs to run before the request; At the moment I am using a MessageHandler.
I can work out whether I should be reading the querystring or formdata based on the method, and when it's a GET I can read the querystring OK using Request.GetQueryNameValuePairs(); however the problem is reading the formdata when it's a POST.
I can get the formdata using Request.Content.ReadAsFormDataAsync(), however formdata can only be read once, and when I read it here it is no longer available for the request (i.e. my controller actions get null models)
What is the most appropriate way to consistently and non-intrusively read querystring and/or formdata from a request before it gets to the request logic?
Regarding your question of which place would be better, in this case i believe the AuthorizationFilters to be better than a message handler, but either way i see that the problem is related to reading the body multiple times.
After doing "Request.Content.ReadAsFormDataAsync()" in your message handler, Can you try doing the following?
Stream requestBufferedStream = Request.Content.ReadAsStreamAsync().Result;
requestBufferedStream.Position = 0; //resetting to 0 as ReadAsFormDataAsync might have read the entire stream and position would be at the end of the stream causing no bytes to be read during parameter binding and you are seeing null values.
note: The ability of a request's content to be read single time only or multiple times depends on the host's buffer policy. By default, the host's buffer policy is set as always Buffered. In this case, you will be able to reset the position back to 0. However, if you explicitly make the policy to be Streamed, then you cannot reset back to 0.
What about using ActionFilterAtrributes?
this code worked well for me
public HttpResponseMessage AddEditCheck(Check check)
{
var request= ((System.Web.HttpContextWrapper)Request.Properties.ToList<KeyValuePair<string, object>>().First().Value).Request;
var i = request.Form["txtCheckDate"];
return Request.CreateResponse(HttpStatusCode.Ok);
}

Calling a webservice using google closures jsonp and sending json as parameter

I want to call a webservice using google closures, via jsonp since i am performing a cross domain webservice.
And i am calling it in the following manner
var url = "http://myurl/";
var jsonp = new goog.net.Jsonp(url);
jsonp.send(
{"name":"jessi","action":"initaction","gameId":"123"},
callback, callbackfailed);
But in this method the url is converted as a normal get method string as the follows
http://myurl/?name=jessi&action=initaction&gameId=123
But i need to send this url as a json object in the following manner
"name":"pari123","action":"initaction","gameId":"slotreel3"
How can i do this, i searched google and i couldnt find proper documentation regarding ?this.
The function goog.net.Jsonp.addPayloadToUri_ that is used to encode the object says:
#param {!Object} payload A map of value name pairs to be encoded.
A value may be specified as an array, in which case a query parameter
will be created for each value, e.g.:
{"foo": [1,2]} will encode to "foo=1&foo=2".
This is exactly what is happening. So, why not initialize your url with the query? e.g.
var url = "http://myurl.php?" + goog.json.serialize({"name":"jessi","action":"initaction","gameId":"123"});
var jsonp = new goog.net.Jsonp(url);
jsonp.send()
Untested but maybe this works.
Regards,
Rene