Webservice POST to secure site

Discussion in 'ASP .Net Web Services' started by Xakware, Nov 21, 2003.

  1. Xakware

    Xakware Guest

    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;

    }
    Xakware, Nov 21, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. A.M
    Replies:
    5
    Views:
    5,420
    Teemu Keiski
    Jun 8, 2004
  2. Daniel Malcolm
    Replies:
    0
    Views:
    545
    Daniel Malcolm
    Jan 24, 2005
  3. zdrakec
    Replies:
    1
    Views:
    428
    zdrakec
    Jul 25, 2005
  4. Joe
    Replies:
    5
    Views:
    947
    Steven Cheng[MSFT]
    Dec 13, 2005
  5. verbal kint
    Replies:
    1
    Views:
    541
    Sudsy
    Sep 4, 2004
Loading...

Share This Page