J
John Saunders
can't find this error (see note below) documented on MSDN.Dave said:Hi,
I'm trying to simulate a form post using the WebRequest class. But I
string strId = "someid";
string strName = "somename";
ASCIIEncoding encoding=new ASCIIEncoding();
string postData="userid="+strId;
postData += ("&username="+strName);
byte[] data = encoding.GetBytes(postData);
Prepare web request...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("https://secure.somecontentwepayfor.com");
myRequest.Method = "POST";
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
newStream.Write(data,0,data.Length); <---**ERROR OCCURS HERE**.
newStream.Close();
WebResponse resp = myRequest.GetResponse();
Throw a try block around that code and display the full exception in the
catch. In addition, if it's a WebException, you may be able to display the
Status property:
try
{
string strId = "someid";
string strName = "somename";
ASCIIEncoding encoding=new ASCIIEncoding();
string postData="userid="+strId;
postData += ("&username="+strName);
byte[] data = encoding.GetBytes(postData);
Prepare web request...
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("https://secure.somecontentwepayfor.com");
myRequest.Method = "POST";
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
newStream.Write(data,0,data.Length); <---**ERROR OCCURS HERE**.
newStream.Close();
WebResponse resp = myRequest.GetResponse();
}
catch (WebException wex)
{
Page.Trace.Write(wex.ToString());
Page.Trace.Write(wex.Status);
}
catch (Exception ex)
{
Page.Trace.Write(ex.ToString());
}