post programmatically

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

    post programmatically

    Hi

    I want to programmaticall y perform a post. Can some one please give me
    some pointers to which classes I need to use to achieve this?

    The form which is normally posted from the website looks like the
    following, but I want to do it programmaticall y.


    <form action="https://intl.payments/recdpay" method="POST"
    target="_top">
    <input type="hidden" name="merchantI D" value="xx7223.1 89" />
    <input type="hidden" name="orderID" value="UK_Z0000 287" />
    <input type="hidden" name="amount" value="59995" />
    <input type="hidden" name="currencyC ode" value="GBP" />
    <input type="hidden" name="cardType" value="6" />
    <input type="submit" value="Pay" />
    </form>



    Thanks,
    Peter
  • Pavel Minaev

    #2
    Re: post programmaticall y


    "Peter" <xdzgor@hotmail .comwrote in message
    news:uxca0WaDJH A.3432@TK2MSFTN GP05.phx.gbl...
    Hi
    >
    I want to programmaticall y perform a post. Can some one please give me
    some pointers to which classes I need to use to achieve this?
    >
    The form which is normally posted from the website looks like the
    following, but I want to do it programmaticall y.
    HttpWebRequest should do the trick, just don't forget to set its Method to
    "POST". Values of form controls go into the request body, which is just a
    stream for WebRequest, so you'll need to format it yourself. W3C HTML 4.01
    spec has detailed description of the format:




    Comment

    • Sin Jeong-hun

      #3
      Re: post programmaticall y

      On Sep 3, 6:16 pm, "Peter" <xdz...@hotmail .comwrote:
      Hi
      >
      I want to programmaticall y perform a post. Can some one please give me
      some pointers to which classes I need to use to achieve this?
      >
      The form which is normally posted from the website looks like the
      following, but I want to do it programmaticall y.
      >
      <form action="https://intl.payments/recdpay" method="POST"
      target="_top">
      <input type="hidden" name="merchantI D" value="xx7223.1 89" />
      <input type="hidden" name="orderID" value="UK_Z0000 287" />
      <input type="hidden" name="amount" value="59995" />
      <input type="hidden" name="currencyC ode" value="GBP" />
      <input type="hidden" name="cardType" value="6" />
      <input type="submit" value="Pay" />
      </form>
      >
      Thanks,
      Peter
      As Pavel Minaev said, HttpWebRequest would be good enough. But
      WebRequest is also good, I think. Basically, as far as I know,
      HttpWebRequest is a superset of WebRequest. You can find many samples
      for it, even the .NET documentation had a section about how to POST a
      request at the How do I section.

      To save your time, I will write a quick code for you, may contain some
      errors, but you can start it from there.

      WebRequest req = WebReqest.Creat e("https://....");
      req.Method="POS T"; <-Default is GET, so need to specify "POST"
      req.ContentType ="applicatio n/x-www-form-urlencoded"; <-This is
      required because there are other types of forms like multipart or
      something.
      Stream s = req.GetRequestS tream();
      string data="merchantI D=xx7223.189&or derID....";
      byte[] binaryData=Enco ding.UTF8.GetBy tes(data); <-Supposing the page's
      encoding is UTF-8. Need to change it in other cases.
      s.Write(binaryD ata,0,binaryDat a.Length);
      s.close();
      req.ContentLeng th=binaryData.L ength;
      WebResponse res =req.GetRespons e();

      Comment

      • Pavel Minaev

        #4
        Re: post programmaticall y

        "Sin Jeong-hun" <typingcat@gmai l.comwrote in message
        news:1dae1315-d2d6-4449-be18-14910345d719@z1 1g2000prl.googl egroups.com...
        On Sep 3, 6:16 pm, "Peter" <xdz...@hotmail .comwrote:
        As Pavel Minaev said, HttpWebRequest would be good enough. But
        WebRequest is also good, I think. Basically, as far as I know,
        HttpWebRequest is a superset of WebRequest. You can find many samples
        for it, even the .NET documentation had a section about how to POST a
        request at the How do I section.
        WebRequest is an abstract class, HttpWebRequest is one specific
        implementation.

        It is generally advised to use WebRequest.Crea te() factory method to
        instantiate any implementation of WebRequest. But it is explicitly allowed
        to cast the return value of WebRequest.Crea te() to the specific type you
        expect to get.

        In this case though, I've missed the fact that WebRequest has property
        Method already (strange, since it's really HTTP-specific, and cannot be
        properly used in a generic fashion anyway), so no need for cast.


        Comment

        Working...