X
Xakware
Hello All,
I am new to this group, so please forgive me if this
question has been addressed. I have written a function that posts data
to a secure website. It works fine when in a console application or a
form, but the same code fails when used as a web method in a
webservice. The error message says that the number of bytes exceeds
the number of bytes specified in the ContentLength of the httprequest
object. Can anyone help me?? The code is below....
[WebMethod]
public string Send_Req(string strRequest)
{
string result;
HttpWebRequest httpRequest =
(HttpWebRequest)WebRequest.Create("https://www.securesite.com/CGI-BIN/CGIProg.exe");
httpRequest.Method = "POST";
httpRequest.ContentLength = strRequest.Length;
httpRequest.ContentType = "application/x-www-form-urlencoded";
X509Certificate myCert =
X509Certificate.CreateFromCertFile(@"C:\test.cer");
httpRequest.ClientCertificates.Add(myCert);
StreamWriter requestWriter = new
StreamWriter(httpRequest.GetRequestStream());
requestWriter.Write(strRequest);
requestWriter.Close();
HttpWebResponse httpResponse =
(HttpWebResponse)httpRequest.GetResponse();
StreamReader resultReader = new
StreamReader(httpResponse.GetResponseStream());
result = resultReader.ReadToEnd();
resultReader.Close();
return result;
}
I am new to this group, so please forgive me if this
question has been addressed. I have written a function that posts data
to a secure website. It works fine when in a console application or a
form, but the same code fails when used as a web method in a
webservice. The error message says that the number of bytes exceeds
the number of bytes specified in the ContentLength of the httprequest
object. Can anyone help me?? The code is below....
[WebMethod]
public string Send_Req(string strRequest)
{
string result;
HttpWebRequest httpRequest =
(HttpWebRequest)WebRequest.Create("https://www.securesite.com/CGI-BIN/CGIProg.exe");
httpRequest.Method = "POST";
httpRequest.ContentLength = strRequest.Length;
httpRequest.ContentType = "application/x-www-form-urlencoded";
X509Certificate myCert =
X509Certificate.CreateFromCertFile(@"C:\test.cer");
httpRequest.ClientCertificates.Add(myCert);
StreamWriter requestWriter = new
StreamWriter(httpRequest.GetRequestStream());
requestWriter.Write(strRequest);
requestWriter.Close();
HttpWebResponse httpResponse =
(HttpWebResponse)httpRequest.GetResponse();
StreamReader resultReader = new
StreamReader(httpResponse.GetResponseStream());
result = resultReader.ReadToEnd();
resultReader.Close();
return result;
}