System.Net.HttpWebRequest with HTTPS

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dgiard

    #1

    System.Net.HttpWebRequest with HTTPS

    I am using the System.Net.Http WebRequest object to POST data to an HTTPS web
    page.

    Other than prefixing the URL with "HTTPS://", do I need to do anything in my
    code to indicate that this is SSL?

    Here is my code:
    // Create Web Request
    string url = "https://something.net/something.dll";

    HttpWebRequest oHttp =
    (HttpWebRequest ) WebRequest.Crea te(url);

    // Post form variables
    string params = "x_Version= " + version
    + "&x_DelimDa ta=" + delimData
    + "&x_Login=" + login
    + "&x_Passwor d=" + password
    + "&x_Amount= " + amount
    + "&x_Card_Nu m=" + cardNumber
    + "&x_Exp_Dat e=" + expirationDate
    + "&x_Type=" + type;
    oHttp.Method="P OST";
    byte [] postBuffer =
    System.Text.Enc oding.GetEncodi ng(1252).GetByt es(params);
    oHttp.ContentLe ngth = postBuffer.Leng th;
    Stream postData = oHttp.GetReques tStream();
    postData.Write( postBuffer,0,po stBuffer.Length );
    postData.Close( );

    // Get results
    HttpWebResponse myResponse = (HttpWebRespons e) oHttp.GetRespon se();
    Encoding enc = System.Text.Enc oding.GetEncodi ng(1252);
    StreamReader loResponseStrea m =
    new StreamReader(my Response.GetRes ponseStream(), enc);
    string retHtml = loResponseStrea m.ReadToEnd();
    myResponse.Clos e();
    loResponseStrea m.Close();

    messages = retHtml;


  • Joerg Jooss

    #2
    Re: System.Net.Http WebRequest with HTTPS

    "dgiard" spoke:
    [color=blue]
    > I am using the System.Net.Http WebRequest object to POST data to an
    > HTTPS web page.
    >
    > Other than prefixing the URL with "HTTPS://", do I need to do
    > anything in my code to indicate that this is SSL?[/color]

    Check out if the framework's default certificate policy (URL below)
    works for you. If not, you need to implement your own. But that should
    be it.

    http://msdn.microsoft.com/library/de...l=/library/en-
    us/cpref/html/frlrfSystemNetS ervicePointMana gerClassCertifi catePolicyTop
    ic.asp

    Cheers,
    --
    Joerg Jooss
    joerg.jooss@gmx .net

    Comment

    • dgiard

      #3
      Re: System.Net.Http WebRequest with HTTPS

      Thanks, Joerg.

      "Joerg Jooss" <joerg.jooss@gm x.net> wrote in message
      news:OfG1RIqTDH A.3132@tk2msftn gp13.phx.gbl...[color=blue]
      > "dgiard" spoke:
      >[color=green]
      > > I am using the System.Net.Http WebRequest object to POST data to an
      > > HTTPS web page.
      > >
      > > Other than prefixing the URL with "HTTPS://", do I need to do
      > > anything in my code to indicate that this is SSL?[/color]
      >
      > Check out if the framework's default certificate policy (URL below)
      > works for you. If not, you need to implement your own. But that should
      > be it.
      >
      > http://msdn.microsoft.com/library/de...l=/library/en-
      > us/cpref/html/frlrfSystemNetS ervicePointMana gerClassCertifi catePolicyTop
      > ic.asp
      >
      > Cheers,
      > --
      > Joerg Jooss
      > joerg.jooss@gmx .net[/color]


      Comment

      Working...