R
Rachet?
I am getting a "The remote server returned an error: (400) Bad
Request." error while trying to send data to an asp page. The puzzle
is, if I paste the string I want to send on a browser address box, it
just go fine. From the win form app also it go fine until I happen to
send an xml formatted string as a value. But same go fine through the
browser.
Any help is greatly appreciated.
My code looks like:
string responseString = null;
string strPost=names[0]+"=" + values[0];
for(int i=1;i<values.Length;i++)
{
strPost += ("&" +names+"=" + values);
}
byte[] encodedRequest = Encoding.UTF8.GetBytes(strPost);
HttpWebRequest httpReq =
(HttpWebRequest)WebRequest.Create(myaspPageURL)
httpReq.ContentType =
"application/x-www-form-urlencoded"; httpReq.Timeout = 10000;
httpReq.KeepAlive = true;
httpReq.UserAgent = null;
httpReq.ContentLength = encodedRequest.Length;
httpReq.Method = "POST";
try
{
using (Stream requestStream = httpReq.GetRequestStream())
{
requestStream.Write(encodedRequest, 0, encodedRequest.Length);
requestStream.Close();
}
}
catch ( Exception ex )
{
return "Error in request : " +ex.Message;
}
try
{
HttpWebResponse httpResp = (HttpWebResponse)httpReq.GetResponse();
using (StreamReader sr = new
StreamReader(httpResp.GetResponseStream()) )
{
do
{
responseString = sr.ReadToEnd();
}while(responseString=="");
sr.Close();
}
httpResp.Close ();
/return the response
return responseString;
}
catch ( Exception ex1 )
{
//status=httpResp.StatusDescription ;
return "Error in response : " +ex1.Message ;
}
}
Request." error while trying to send data to an asp page. The puzzle
is, if I paste the string I want to send on a browser address box, it
just go fine. From the win form app also it go fine until I happen to
send an xml formatted string as a value. But same go fine through the
browser.
Any help is greatly appreciated.
My code looks like:
string responseString = null;
string strPost=names[0]+"=" + values[0];
for(int i=1;i<values.Length;i++)
{
strPost += ("&" +names+"=" + values);
}
byte[] encodedRequest = Encoding.UTF8.GetBytes(strPost);
HttpWebRequest httpReq =
(HttpWebRequest)WebRequest.Create(myaspPageURL)
httpReq.ContentType =
"application/x-www-form-urlencoded"; httpReq.Timeout = 10000;
httpReq.KeepAlive = true;
httpReq.UserAgent = null;
httpReq.ContentLength = encodedRequest.Length;
httpReq.Method = "POST";
try
{
using (Stream requestStream = httpReq.GetRequestStream())
{
requestStream.Write(encodedRequest, 0, encodedRequest.Length);
requestStream.Close();
}
}
catch ( Exception ex )
{
return "Error in request : " +ex.Message;
}
try
{
HttpWebResponse httpResp = (HttpWebResponse)httpReq.GetResponse();
using (StreamReader sr = new
StreamReader(httpResp.GetResponseStream()) )
{
do
{
responseString = sr.ReadToEnd();
}while(responseString=="");
sr.Close();
}
httpResp.Close ();
/return the response
return responseString;
}
catch ( Exception ex1 )
{
//status=httpResp.StatusDescription ;
return "Error in response : " +ex1.Message ;
}
}