471,344 Members | 1,566 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,344 software developers and data experts.

HttpPost

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
Jun 27 '08 #1
5 6346
On May 16, 10:51 am, "Dave" <D...@newsgroup.nospamwrote:
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.
Jun 27 '08 #2
"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();
Jun 27 '08 #3
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/steve...netscrape2.asp

http://weblogs.asp.net/ngur/archive/...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:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "Dave" <DW**@newsgroup.nospam>
Subject: HttpPost
Date: Fri, 16 May 2008 10:51:45 -0400
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
Jun 27 '08 #4
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:
ms****@microsoft.com.

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

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: st*****@online.microsoft.com (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/steve...netscrape2.asp

http://weblogs.asp.net/ngur/archive/...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:
ms****@microsoft.com.

================================================= =
Get notification to my posts through email? Please refer to
http
Jun 27 '08 #5
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.CustomerInformationData Table

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

What could be wrong here?

THanks in advance!
Ron
"Steven Cheng [MSFT]" wrote:
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:
ms****@microsoft.com.

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

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: st*****@online.microsoft.com (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/steve...netscrape2.asp

http://weblogs.asp.net/ngur/archive/...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:
ms****@microsoft.com.

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

Jul 20 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by John A Grandy | last post: by
1 post views Thread by Kevin Landymore | last post: by
reply views Thread by Edmund Green | last post: by
reply views Thread by Matthew Lock | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.