problem with using WebRequest class in C#
hi all,
i'm generating a webrequest afte a user submits his form.
but i'm getting the following error:
The underlying connection was closed: The remote name could not be resolved
can anyone help me out please?
here is the code i'm using:
string result = "";
WebRequest req = WebRequest.Create("Url here");
//i'm getting error from the following line
WebResponse webresponse = req.GetResponse();
Stream ReceiveStream = webresponse.GetResponseStream();
Byte[] read = new Byte[512];
int bytes = ReceiveStream.Read(read, 0, 512);
while (bytes > 0)
{
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
result = result + encode.GetString(read, 0, bytes);
bytes = ReceiveStream.Read(read, 0, 512);
}
// the response contains name value pairs separated by commas
string[] response = result.Split(',');
string key;
string valuePart;
NameValueCollection nr = new NameValueCollection();
int i = 0;
foreach (string xx in response)
{
i = xx.IndexOf("=");
key = xx.Substring(0,i);
valuePart = xx.Substring(i + 1);
nr.Add(key,valuePart);
}
|