Webservice POST to secure site

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;

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top