0

I am able to read the url and entire page but not able to read the HTTP POST Request Message Parameters in c#. In my situation i am posting a post url to a site after they verify they send me a HTTP Post message with parameters like id.

here is my code in c#

HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(uri);

postsourcedata = "processing=true&Sal=5000000";

request1.Method = "POST";
request1.ContentType = "application/x-www-form-urlencoded";
request1.ContentLength = postsourcedata.Length;
request1.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
Stream writeStream1 = request1.GetRequestStream();
UTF8Encoding encoding1 = new UTF8Encoding();
byte[] bytes1 = encoding1.GetBytes(postsourcedata);
writeStream1.Write(bytes1, 0, bytes1.Length);
writeStream1.Close(); 
HttpWebResponse response =   (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8);
string page = readStream.ReadToEnd();
//page.Close();
return page.ToString();

They are sending me request parameters like id and text , how to read these parameters on my side.I am posting to the website through a web service.

Can anyone help me with this?

1 Answer 1

2

If they are sending you an HTTP Post message that means that you either need to have a web server or something that understands HTTP protocol to handle the requests, correct?

What I mean is that by your description, it looks like they are sending you an HTTP Request to port 80 or port 443 (https) and you should have asp.net page to handle the request. Once they hit that page, you can simply do:

Request.Parameters("Id")
Request.Parameters("Text")

And so on.

Sign up to request clarification or add additional context in comments.

4 Comments

In my situation i am doing a post url to their site using webservice method and they again post back with parameters i need to capture the parameters in that one only.
@Shesi okay, so you have a website and they are posting back to it. Do you know what page they post back to ? For you it's a regular HTTP Request that you can handle on Page_Load. I would imagine they post back to the page where the action originated.
yes they are posting back to the webservice is it possible to read the parameters in the web method, i tried request.RequestUri I am able to get the url from which it is responding but not the parameters
I believe every parameter in the post message must match a parameter in the WebMethod. For example, if they call your WebMethod Foo via Post, passing Id and Text as Parameters in the HTTP Post Request, then your WebMethod signature should be like this: [WebMethod] public void Foo(string id, string text) {//code here}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.