3

I have a URL and data is being posted on that URL through ERP software from another vendor.....I want to collect the data posted on my URL in page load event from that vendor....What should be done for that in ASP.NET with c#? He does not have a field name and he is auto-generating the string of data and then posting it automatically to my ASP.NET page.

5 Answers 5

2

First if you know what kind of data you're going to receive then you should add:

Page.Response.ContentType = "text/xml"; //For XML Data

Then read that data in stream reader:

StreamReader sr = new StreamReader(Page.Request.InputStream);

The data in streamreader is Url Encoded. So you've to decode it before you use that further:

string main = Server.UrlDecode(sr.ReadToEnd());

That's all. I hope it helps.

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

Comments

1
var parameter = Request.QueryString["parameterName"];

if (parameter != null)
{
 //.. use it
}

See HttpRequest.QueryString

1 Comment

they are not sending data through querystring
0

I understand you said that the Query doesn't have a field name; meaning you can't look for it like a normal QueryString, using the string indexer. If so, then you probably have to access it without knowing the query key.

assuming you know that the 'data' is the first parameter, you could access it like this:

string data = Request.QueryString.getKey(0);

If that won't work, you can access the url directly

string query = Request.Url.Query;

Comments

0

If they are doing a POST, you can use Request.Form. It will return a NameValueCollection of the elements posted to the Url, and you can loop through it if you don't know the name of what is being posted. If you know the name, then you can do Request.Form["NamedItem"].

Comments

0
foreach(var key in Request)
{
    var data = Request[key];
}

will iterate through Request.Querystrung, Request.Form, and Request.Params.

Comments

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.