System.Net.WebException - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

System.Net.WebException

ITAITA Posts: 463Member
Whenever I submit my webform I recieve a System.Net.WebException error. I am sending some information using POST My code is listed below. Can anyone find the error - the line which is causing the error has been marked. Please help, many thanks. ITA

[code]
public void SubmitBtn_Click(object sender, System.EventArgs e)
{

try
{
// get values entered by the user
string b_surnameSend = b_surname.Text;
string b_firstnameSend = b_firstname.Text;
string emailSend = email.Text;
string b_zipSend = b_zip.Text;
string b_telSend = b_tel.Text;
string s_surnameSend = s_surname.Text;
string s_firstnameSend = s_firstname.Text;
string s_emailSend = s_email.Text;
string s_zipSend = s_zip.Text;
string s_telSend = s_tel.Text;
string s_countrySend = s_Country.SelectedItem.Text;
string companyIdSend = companyid.Value;
string cycleSend = cycle.Value;
string totalperiodSend = totalperiod.Value;
string productQuantitySend = axQty.Text;
string countrySelect = b_Country.SelectedItem.Value;


ASCIIEncoding encoding = new ASCIIEncoding();

// add all values in the form to 1 string called postData
string postData = "firstname = " + b_firstnameSend;
postData += ("&b_surname = " + b_surnameSend);
postData += ("&b_email = " + emailSend);
postData += ("&b_zip = " + b_zipSend);
postData += ("&b_Country = " + countrySelect);
postData += ("&b_tel = " + b_telSend);
postData += ("&s_surname = " + s_surnameSend);
postData += ("&s_firstname = " + s_firstnameSend);
postData += ("&s_email = " + s_emailSend);
postData += ("&s_zip = " + s_zipSend);
postData += ("&s_tel = " + s_telSend);
postData += ("&s_country = " + s_countrySend);
postData += ("&delivery = " + delivery.Value);
postData += ("&companyid = " + companyIdSend);
postData += ("&cycle = " + cycleSend);
postData += ("&totalperiod = " + totalperiodSend);
postData += ("&productQuantity = " + productQuantitySend);



byte[] data = encoding.GetBytes(postData);

// Prepare web request...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("somewebpage.htm");
myRequest.Method = "POST";
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream(); // this line is causing the error

// Send the data
newStream.Write(data,0,data.Length);
newStream.Close();
Response.Redirect("somewebpage.htm");
}
catch(System.Net.WebException)
{
Response.Redirect("error.htm");

}
}
[/code]
Sign In or Register to comment.