Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello friends Good Morning

I am facing a problem from last few days.. I have a window application which is sending request to another applications and it get the response from other application.
Now the problem is this that if i run my application in any another system i will get the response from from another application but when i use this application in my system then its throw an exception that

CONNECTION WAS ABORTED BY HOST MACHINE

please tell me why it is happening here is the my code which i am using

C#
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";

}


Please tell me what is going wrong if you get it
Posted
Updated 18-Apr-13 19:28pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900