Hello everyone
I am posting the same question again. Because i did not get any reply from my previous question.
I am working on an application. Its a window application which developed in .net 2.0
Now the problem is this that when ever i run my application and i send a request to another application its send successfully but i get the problem when i get the response its show me the error and the error is
The underlying connection was closed: An unexpected error occurred on a receive.
here is my code
public string tm4b(string sURL, bool bEscapeURL, string sPostData)
{
sURL = sURL.Trim();
while (sURL.IndexOf(" ") > 0)
{
sURL = sURL.Replace(" ", " ");
}
System.Text.StringBuilder sb = new System.Text.StringBuilder();
string stmp = string.Empty;
Uri httpUri = new Uri(sURL, bEscapeURL);
try
{
System.Text.ASCIIEncoding byteConverter = new System.Text.ASCIIEncoding();
byte[] byte1 = byteConverter.GetBytes(sPostData);
System.Net.HttpWebRequest hwRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(httpUri);
hwRequest.ContentType = "application/x-www-form-urlencoded";
hwRequest.Method = "POST";
hwRequest.ContentLength = sPostData.Length; ;
System.IO.Stream PostStream = hwRequest.GetRequestStream();
PostStream.Write(byte1, 0, byte1.Length);
System.Net.HttpWebResponse hwResponse = (System.Net.HttpWebResponse)hwRequest.GetResponse();
System.IO.StreamReader sRead = new System.IO.StreamReader(hwResponse.GetResponseStream(),
System.Text.Encoding.ASCII);
if ((stmp = sRead.ReadLine()) != null)
{
sb.Append(stmp + "");
}
PostStream.Close();
sRead.Close();
return sb.ToString();
}
catch (Exception ex)
{
return "error";
}
return "Request Error";
}
But its give me this error for only one url and for anothers url its working well
Please check the code and error and please tell me what i have to do
i tried all the logics that i can use but did not get any good results
So experts please help me