HttpPost

D

Dave

I'm writing an app that needs to send info to a client by their specs,

m_request= "https://website.com/app?xml=xml_file&xmlString=<?xml
version='1.0' encoding='utf-8' ?>xmlfilecontentset...etc</endfile>"
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_request);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Which works fine for a small file, 3k or less, but for a file with more
items in the xml file the server return a "500 Internal Server Error"

Is the HTTPWebResponse call basically a send statement instead of an
HttpPost? How would I do an HttpPost?

Thanks
 
P

parez

I'm writing an app that needs to send info to a client by their specs,

m_request= "https://website.com/app?xml=xml_file&xmlString=<?xml
version='1.0' encoding='utf-8' ?>xmlfilecontentset...etc</endfile>"
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_request);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Which works fine for a small file, 3k or less, but for a file with more
items in the xml file the server return a "500 Internal Server Error"

Is the HTTPWebResponse call basically a send statement instead of an
HttpPost? How would I do an HttpPost?

Thanks

You are probably exceeding the querystring limit. Most browsers limit
it to between 2k-3k. In this case, its getting exceeded on the server
side.

for posting you could use WebClient.UploadString method.
 
A

AdemusPrime

"500 Internal Server Error" is a problem on the server side not the
client side (your code).

The URL in a request has a size limit. You may be overflowing this
limit with a very large string.

You can use the WebClient object to .UploadString or .UploadValues for
name/value pairs but this limits your properties you can set.

I typically use the following just like a FORM POST.

HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(@"http://website.com/webapp/
page.aspx");
req.Credentials = new NetworkCredential("name",
"pass");
req.KeepAlive = true;
req.Method = "POST"; //must be uppercase on some
webservers
req.ContentType = @"text/xml";
req.ProtocolVersion = HttpVersion.Version11;
using (StreamWriter writer = new
StreamWriter(req.GetRequestStream()))
{
string uploadString = "xml=xml_file&xmlString=" +
data; //where data is your predefined payload
writer.WriteLine(uploadString);
}
WebResponse res = req.GetResponse();
StreamReader read = new
StreamReader(res.GetResponseStream());
string fullResponse = read.ReadToEnd();
 
S

Steven Cheng [MSFT]

Hi Dave,

As other members have mentioned, the error you encounter is likely due to
the data you appened in request's url(querystring) has exceeded the max
length of the http querystring limit. Normally, for very large data, HTTP
POST protocol is surely the recommended means to post them.

As for how to do http post with .NET component, you can use either
WebClient or HttpWebRequest class. For webrequest class, you need to open
the "RequestStream" of it and then write the message body(you want to
transfer) into the requeststream and then send it. AdemusPrime has posted
some detailed code sample in his message, you can have a look.

Here are some other web article provided sample code of doing http post
with .NET webrequest component:

http://authors.aspalliance.com/stevesmith/articles/netscrape2.asp

http://weblogs.asp.net/ngur/archive/2004/05/11/129951.aspx

http://www.netomatix.com/httppostdata.aspx

Hope this also helps some.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 
S

Steven Cheng [MSFT]

Hi Dave,

Have you got any progress? If there is anything else need help, welcome to
post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: (e-mail address removed) (Steven Cheng [MSFT])
Organization: Microsoft
Date: Mon, 19 May 2008 02:36:47 GMT
Subject: RE: HttpPost
 
D

DoctorDotNet

Steve,
I am using the WebClient and receiving this (500) Internal Server Error
message.

Here is my code for sending my XML data:
Dim strXML As String = "<?xml version='1.0' encoding='utf-8'?>" &
CustomerInformation.DataSet.GetXml()
'Dim XmlData() As Byte =
System.Text.Encoding.UTF8.GetBytes(strXML.ToString())
Dim WebClient As New System.Net.WebClient()
WebClient.Headers.Add("Content-Type", "text/xml")
WebClient.Encoding = System.Text.Encoding.UTF8
CustomerNumber = WebClient.UploadString(New Uri(RegURI &
"RegisterClient.aspx"), strXML.ToString)

Here is my code for receiving the XML Data in RegisterClient.aspx:
Request.ContentType = "application/x-www-form-urlencoded"
Request.ContentEncoding = System.Text.Encoding.UTF8


Dim CustomerInformation As New
ENv.ClientRegistrationData.CustomerInformationDataTable

Try
CustomerInformation.ReadXml(Request.InputStream)
Catch ex As Exception
Exit Sub
End Try

What could be wrong here?

THanks in advance!
Ron


Steven Cheng said:
Hi Dave,

Have you got any progress? If there is anything else need help, welcome to
post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: (e-mail address removed) (Steven Cheng [MSFT])
Organization: Microsoft
Date: Mon, 19 May 2008 02:36:47 GMT
Subject: RE: HttpPost
Hi Dave,

As other members have mentioned, the error you encounter is likely due to
the data you appened in request's url(querystring) has exceeded the max
length of the http querystring limit. Normally, for very large data, HTTP
POST protocol is surely the recommended means to post them.

As for how to do http post with .NET component, you can use either
WebClient or HttpWebRequest class. For webrequest class, you need to open
the "RequestStream" of it and then write the message body(you want to
transfer) into the requeststream and then send it. AdemusPrime has posted
some detailed code sample in his message, you can have a look.

Here are some other web article provided sample code of doing http post
with .NET webrequest component:

http://authors.aspalliance.com/stevesmith/articles/netscrape2.asp

http://weblogs.asp.net/ngur/archive/2004/05/11/129951.aspx

http://www.netomatix.com/httppostdata.aspx

Hope this also helps some.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http
 

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