Using HttpResponse succeeds only after several tries

R

redmond

Using the below code for posting xml content throws "Badrequest (400)" and
only succeeeds after 3 or 4 tries. Hugely appreciate if somebody knows how to
fix this.

oHttpRequest =
(HttpWebRequest)WebRequest.Create(GlobalConfiguration.GetPartnerSetting(PARTNER_NAME, "ResidentURL"));
oHttpRequest.Timeout =
int.Parse(GlobalConfiguration.GetPartnerSetting(PARTNER_NAME,
"GatewayTimeoutMS"));
oHttpRequest.Method = "post";
oHttpRequest.ContentType = "text/xml";
oHttpRequest.ContentLength = arrPostData.Length;
//The foloowing
oHttpRequest.AllowWriteStreamBuffering = true;
oHttpRequest.KeepAlive = true;

oRequestStream = oHttpRequest.GetRequestStream();
oRequestStream.Write(arrPostData, 0, arrPostData.Length);
oRequestStream.Flush();
oRequestStream.Close();

//Make the request to the remote server
try
{
//This is where it
throws the BadRequest error
oHttpResponse = (HttpWebResponse)oHttpRequest.GetResponse();
}
catch (Exception ex)
{
throw new ApplicationException("The remote server could not be
contacted. " + ex.Message + ".", ex);
}
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top