How to read Request Body values in ASP.NET

G

Guest

I am trying to read Http request body values NOT form values
The content type is text/xml and its POST
I am posting data from Infopath to an asp.net page.

In ASP it works by just writing Response.Write(request) the same does not
work in ASP.NET

I tried using Rquest.BinaryrRead() and Request.InputStream but it gives me
text values as space separated (eg Karthik yyyy aaaa) whereas the data i am
looking out for is in XML format.
When I tried saving the Request object to a file using
Request.SaveAs("c:\\request.txt, false), it file contained xml text in the
format which I required.
In ASP too I get this xml string easily by get getting the request object.

Help me with a solution.

Thanks,
Karthik
 
P

Patrice

What if you use "view source" instead of just looking at the text in a
browser (remember that the browser will ignore unkown tags).

Else explains a bit more what you are doing when you are not saving the file
(for now I assume you displayed the result in your browser as an HTML
cotnent type).
 
G

Guest

I want to read the xml data which is there in the request body, do some
process and insert into a database.
Currently, I am unable to read the xml data in the request body, unless i
save it to a file and then read the file.

Karthik
 
P

Patrice

How do you post those data (as a file or as a field ?). How do you read this
content ?

At this point I believe you'll have to provide the minimal amount of code
that repro the problem (and it"s likely you'll discover what gores wrong in
this process).

--
 
G

Guest

I post the data from an Infopath form.
In the ASP.Net page i use the following code.
str = Request.InputStream;
strLen = int.Parse(str.Length.ToString());
byte[] strArr = new byte[strLen];
strRead = str.Read(strArr,0,strLen);
Response.Write(System.Text.Encoding.ASCII.GetString(strArr, 0, strLen));

// this print Karthik aaa bbb cccc

I want data in this format, data taken from saved request object for which i
used
System.Web.HttpContext.Current.Request.SaveAs("c:\\request.txt",false);

<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution
solutionVersion="1.0.0.7" productVersion="11.0.6565" PIVersion="1.0.0.0"
href="file:///C:\Documents%20and%20Settings\J910472\My%20Documents\financedeclaration.xsn"
name="urn:schemas-microsoft-com:blush:ffice:infopath:financedeclaration:-myXSD-2005-05-20T03-34-42"
?><?mso-application progid="InfoPath.Document"?><my:myFields
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-05-20T03:34:42"
xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-us">
<my:txtEmployeeName>Karthik</my:txtEmployeeName>
<my:txtEmployeeCode>0000</my:txtEmployeeCode>
<my:txtPANNumber>Applied</my:txtPANNumber>
<my:Gender>Male</my:Gender>
<my:txtResidentialAddress>skjfdkfjdkf dfjkfjdf</my:txtResidentialAddress>
<my:blnRentedHouse>false</my:blnRentedHouse>
<my:txtHouseLocated>dddd</my:txtHouseLocated>
<my:txtRentPerMonth>0.0</my:txtRentPerMonth>
<my:txtMonthsinRentedHouse>0</my:txtMonthsinRentedHouse>
<my:txt80D>0.0</my:txt80D>
<my:txt80DD>0.0</my:txt80DD>
<my:txt80DDB>0.0</my:txt80DDB>
<my:txt80E>0.0</my:txt80E>
<my:txt80G>0.0</my:txt80G>
<my:txt80GG>0.0</my:txt80GG>
<my:txtOther>0.0</my:txtOther>
<my:txtPensionFund>0.0</my:txtPensionFund>
<my:txtNSC>0.0</my:txtNSC>
<my:txtPPF>0.0</my:txtPPF>
<my:txtIB>0.0</my:txtIB>
<my:txtCE>0.0</my:txtCE>
<my:txtHLP>0.0</my:txtHLP>
<my:txtInsurance>0.0</my:txtInsurance>
<my:txtOtherDeduction>0.0</my:txtOtherDeduction>
<my:blnHouseOccupied>true</my:blnHouseOccupied>
<my:blnLoanB41999>true</my:blnLoanB41999>
<my:txtRentfromHouse>0.0</my:txtRentfromHouse>
<my:txtLoanInterest>0.0</my:txtLoanInterest>
<my:Note></my:Note>
</my:myFields>

Thanks,
Karthik
 
P

Patrice

Ok, have you tried my first suggestion ?

Here it looks like you are writing the XML file inside an HTML page. As XML
tags are not recognized as valid HTML Tags by the browsers they are just not
shown in your output.

So use "View source" in your browser to see what the actual content of the
page instead of relying on what you see in your browser... Do you see those
tags when using "View source" ?

--
Patrice

Karthik said:
I post the data from an Infopath form.
In the ASP.Net page i use the following code.
str = Request.InputStream;
strLen = int.Parse(str.Length.ToString());
byte[] strArr = new byte[strLen];
strRead = str.Read(strArr,0,strLen);
Response.Write(System.Text.Encoding.ASCII.GetString(strArr, 0, strLen));

// this print Karthik aaa bbb cccc

I want data in this format, data taken from saved request object for which i
used
System.Web.HttpContext.Current.Request.SaveAs("c:\\request.txt",false);

<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution
solutionVersion="1.0.0.7" productVersion="11.0.6565" PIVersion="1.0.0.0"
href="file:///C:\Documents%20and%20Settings\J910472\My%20Documents\financede
claration.xsn"name="urn:schemas-microsoft-com:blush:ffice:infopath:financedeclaration:-myXSD-20
05-05-20T03-34-42"
?><?mso-application progid="InfoPath.Document"?><my:myFields
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-05-20
T03:34:42"
xml:lang="en-us">
<my:txtEmployeeName>Karthik</my:txtEmployeeName>
<my:txtEmployeeCode>0000</my:txtEmployeeCode>
<my:txtPANNumber>Applied</my:txtPANNumber>
<my:Gender>Male</my:Gender>
<my:txtResidentialAddress>skjfdkfjdkf dfjkfjdf</my:txtResidentialAddress>
<my:blnRentedHouse>false</my:blnRentedHouse>
<my:txtHouseLocated>dddd</my:txtHouseLocated>
<my:txtRentPerMonth>0.0</my:txtRentPerMonth>
<my:txtMonthsinRentedHouse>0</my:txtMonthsinRentedHouse>
<my:txt80D>0.0</my:txt80D>
<my:txt80DD>0.0</my:txt80DD>
<my:txt80DDB>0.0</my:txt80DDB>
<my:txt80E>0.0</my:txt80E>
<my:txt80G>0.0</my:txt80G>
<my:txt80GG>0.0</my:txt80GG>
<my:txtOther>0.0</my:txtOther>
<my:txtPensionFund>0.0</my:txtPensionFund>
<my:txtNSC>0.0</my:txtNSC>
<my:txtPPF>0.0</my:txtPPF>
<my:txtIB>0.0</my:txtIB>
<my:txtCE>0.0</my:txtCE>
<my:txtHLP>0.0</my:txtHLP>
<my:txtInsurance>0.0</my:txtInsurance>
<my:txtOtherDeduction>0.0</my:txtOtherDeduction>
<my:blnHouseOccupied>true</my:blnHouseOccupied>
<my:blnLoanB41999>true</my:blnLoanB41999>
<my:txtRentfromHouse>0.0</my:txtRentfromHouse>
<my:txtLoanInterest>0.0</my:txtLoanInterest>
<my:Note></my:Note>
</my:myFields>

Thanks,
Karthik
Karthik said:
I am trying to read Http request body values NOT form values
The content type is text/xml and its POST
I am posting data from Infopath to an asp.net page.

In ASP it works by just writing Response.Write(request) the same does not
work in ASP.NET

I tried using Rquest.BinaryrRead() and Request.InputStream but it gives me
text values as space separated (eg Karthik yyyy aaaa) whereas the data i am
looking out for is in XML format.
When I tried saving the Request object to a file using
Request.SaveAs("c:\\request.txt, false), it file contained xml text in the
format which I required.
In ASP too I get this xml string easily by get getting the request object.

Help me with a solution.

Thanks,
Karthik
 
G

Guest

Thanks Patrice. It works..
I somehow overlooked it.

Karthik



Patrice said:
Ok, have you tried my first suggestion ?

Here it looks like you are writing the XML file inside an HTML page. As XML
tags are not recognized as valid HTML Tags by the browsers they are just not
shown in your output.

So use "View source" in your browser to see what the actual content of the
page instead of relying on what you see in your browser... Do you see those
tags when using "View source" ?

--
Patrice

Karthik said:
I post the data from an Infopath form.
In the ASP.Net page i use the following code.
str = Request.InputStream;
strLen = int.Parse(str.Length.ToString());
byte[] strArr = new byte[strLen];
strRead = str.Read(strArr,0,strLen);
Response.Write(System.Text.Encoding.ASCII.GetString(strArr, 0, strLen));

// this print Karthik aaa bbb cccc

I want data in this format, data taken from saved request object for which i
used
System.Web.HttpContext.Current.Request.SaveAs("c:\\request.txt",false);

<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution
solutionVersion="1.0.0.7" productVersion="11.0.6565" PIVersion="1.0.0.0"
href="file:///C:\Documents%20and%20Settings\J910472\My%20Documents\financede
claration.xsn"name="urn:schemas-microsoft-com:blush:ffice:infopath:financedeclaration:-myXSD-20
05-05-20T03-34-42"
?><?mso-application progid="InfoPath.Document"?><my:myFields
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-05-20
T03:34:42"
xml:lang="en-us">
<my:txtEmployeeName>Karthik</my:txtEmployeeName>
<my:txtEmployeeCode>0000</my:txtEmployeeCode>
<my:txtPANNumber>Applied</my:txtPANNumber>
<my:Gender>Male</my:Gender>
<my:txtResidentialAddress>skjfdkfjdkf dfjkfjdf</my:txtResidentialAddress>
<my:blnRentedHouse>false</my:blnRentedHouse>
<my:txtHouseLocated>dddd</my:txtHouseLocated>
<my:txtRentPerMonth>0.0</my:txtRentPerMonth>
<my:txtMonthsinRentedHouse>0</my:txtMonthsinRentedHouse>
<my:txt80D>0.0</my:txt80D>
<my:txt80DD>0.0</my:txt80DD>
<my:txt80DDB>0.0</my:txt80DDB>
<my:txt80E>0.0</my:txt80E>
<my:txt80G>0.0</my:txt80G>
<my:txt80GG>0.0</my:txt80GG>
<my:txtOther>0.0</my:txtOther>
<my:txtPensionFund>0.0</my:txtPensionFund>
<my:txtNSC>0.0</my:txtNSC>
<my:txtPPF>0.0</my:txtPPF>
<my:txtIB>0.0</my:txtIB>
<my:txtCE>0.0</my:txtCE>
<my:txtHLP>0.0</my:txtHLP>
<my:txtInsurance>0.0</my:txtInsurance>
<my:txtOtherDeduction>0.0</my:txtOtherDeduction>
<my:blnHouseOccupied>true</my:blnHouseOccupied>
<my:blnLoanB41999>true</my:blnLoanB41999>
<my:txtRentfromHouse>0.0</my:txtRentfromHouse>
<my:txtLoanInterest>0.0</my:txtLoanInterest>
<my:Note></my:Note>
</my:myFields>

Thanks,
Karthik
Karthik said:
I am trying to read Http request body values NOT form values
The content type is text/xml and its POST
I am posting data from Infopath to an asp.net page.

In ASP it works by just writing Response.Write(request) the same does not
work in ASP.NET

I tried using Rquest.BinaryrRead() and Request.InputStream but it gives me
text values as space separated (eg Karthik yyyy aaaa) whereas the data i am
looking out for is in XML format.
When I tried saving the Request object to a file using
Request.SaveAs("c:\\request.txt, false), it file contained xml text in the
format which I required.
In ASP too I get this xml string easily by get getting the request object.

Help me with a solution.

Thanks,
Karthik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top