all groups > c# > april 2006 >
You're in the

c#

group:

Post XML from one C# web app to another


Post XML from one C# web app to another ramsamant NO[at]SPAM gmail.com
4/27/2006 10:30:40 PM
c#:
Hi,

I am trying to push XML files via HTTP using C#. I am using the free
Visual Studio Web Developer Express to do this. After transferring
about 10-15 files, randomly the files transfer fail and I get
[WebException: The remote server returned an error: (403) Forbidden.]

I've tried on XP as well as Win2003 Server

Thanks for any help

Ram

CODE TO SEND FILES.

StringBuilder sb = new StringBuilder();

byte[] bytes = Encoding.UTF8.GetBytes(xml);
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
request.Timeout = 300000;
request.Method = "POST";
request.ContentLength = bytes.Length;
request.ContentType = "text/xml";
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Length);
}

HttpWebResponse response = (HttpWebResponse) request.GetResponse();




CODE TO RECEIVE FILES

byte[] buf = new byte[Request.ContentLength];
buf=Request.BinaryRead(Request.ContentLength);
string s=Encoding.UTF8.GetString(buf);

StringReader sr=new StringReader(s);
DataSet ds=new DataSet();
ds.ReadXml(sr);

\ds.WriteXml(AppDomain.CurrentDomain.BaseDirectory + "/Received/" +
System.DateTime.Now.ToFileTimeUtc().ToString()+".xml");
Re: Post XML from one C# web app to another Greg Young [MVP]
4/28/2006 3:24:20 AM
what is the value of "url" when it fails?

Cheers,

Greg
[quoted text, click to view]

Re: Post XML from one C# web app to another ramsamant NO[at]SPAM gmail.com
4/28/2006 7:12:03 AM
URL remains the same. It is the URL of the receiving application.

I have narrowed it down to the code at the receiving application -
buf=Request.BinaryRead(Request.ContentLength);

I tried it with Request.ToString();

Same thing. It freezes up and returns a 403 error after processing
about 12-15 files.

Thanks,
Ram
AddThis Social Bookmark Button