Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Get the HTTP Post data in C#?

I am using Mailgun API. There is a section that I need to provide a URL to them, then they are going to HTTP Post some data to me.

I provide this URL (http://test.com/MailGun/Webhook.aspx) to Mailgun, so they can Post data. I have a list of parameter names that they are sending like (recipient,domain, ip,...).

I am not sure how get that posted data in my page. In Webhook.aspx page I tried some code as follows but all of them are empty.

 lblrecipient.text= Request.Form["recipient"];   lblip.Text= Request.Params["ip"];   lbldomain.Text = Request.QueryString["domain"]; 

Not sure what to try to get the posted data?

like image 871
Alma Avatar asked Nov 22 '13 18:11

Alma


People also ask

Can we GET data with post method?

Can I use POST method to get data from the server and GET method to post data to the server? A POST request can have a response, but a GET request can't have a body (well technically it can, but there's surprisingly few systems that support it). Therefore this question makes no sense.

What is HTTP POST example?

HTTP works as a request-response protocol between a client and a server in a format that both HTTP clients and servers can understand. For example, when a user uploads a document to the server, the browser sends an HTTP POST request and includes the document in the body of the POST message.

How do I make a HTTP POST Web request?

Make an HTTP POST Web Request With the HttpWebRequest Class in C# The HttpWebRequest class provides methods to interact directly with the server using HTTP protocol in C#. We can use the HttpWebRequest. Method = "POST" property to specify that an HTTP web request is a POST request in C#.

What is POST and GET in HTTP?

HTTP POST requests supply additional data from the client (browser) to the server in the message body. In contrast, GET requests include all required data in the URL.


1 Answers

This code will list out all the form variables that are being sent in a POST. This way you can see if you have the proper names of the post values.

string[] keys = Request.Form.AllKeys; for (int i= 0; i < keys.Length; i++)  {    Response.Write(keys[i] + ": " + Request.Form[keys[i]] + "<br>"); } 
like image 179
James Lawruk Avatar answered Sep 20 '22 04:09

James Lawruk