1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Posting data to a website

Discussion in 'Scripting & Programming' started by ThomasMc, Aug 20, 2008.

  1. ThomasMc

    ThomasMc Gigabyte Poster

    1,507
    49
    111
    Afternoon lads, just a small query today I'm trying to send data from a windows program(form) to a website via the POST method(can't use GET), had a dig about on google but all i could find are ASP.NET examples and none seem to work on the win form, so here's my question

    Can this be done in VB.NET?

    Thanks in advance :)
     
    Certifications: MCDST|FtOCC
    WIP: MCSA(70-270|70-290|70-291)
  2. Fergal1982

    Fergal1982 Petabyte Poster

    4,196
    171
    211
    There should be a method. What exactly is this for? And are you in control of the receiving website?
     
    Certifications: ITIL Foundation; MCTS: Visual Studio Team Foundation Server 2010, Administration
    WIP: None at present
  3. ThomasMc

    ThomasMc Gigabyte Poster

    1,507
    49
    111
    Its a small protx app(for back office cc payments) consisting of a form and a web browser, the form is used to collect the data and then POST it to the website that will be loaded into the browser. I have no control of the receiving website.
     
    Certifications: MCDST|FtOCC
    WIP: MCSA(70-270|70-290|70-291)
  4. Matthew Tailor

    Matthew Tailor Banned

    18
    0
    0
    You can do it in .net. Firstly what kind of data are you posting? XML is probably the most likely these days so you need to use System.Net namespace in .net and the WebRequest method. See below:

    WebRequest webRequest = HttpWebRequest.Create("URL of the site")
    webRequest.ContentType = "text/xml";
    webRequest.Method = "POST";

    then..

    get the stream from the webRequest using webRequest.GetRequestStream. Write your data into this stream in text or xml format.

    Complete the call using:

    webRequest.GetResponse()

    Job done! :biggrin
     
    Certifications: MCSD, MCPD
    WIP: MCPD 2008 (3.5)
  5. Fergal1982

    Fergal1982 Petabyte Poster

    4,196
    171
    211
    Im not entirely sure I follow you to be honest. You are trying to create a winform to collect data, and send it to a webpage. What exactly are you expecting it to do then? Should it open a webpage? or should it return data to the winform?

    By the looks of things, you are wanting to open a browser for the user, and direct that browser to the webpage, posting the data. I'm not entirely sure that this can be done to be perfectly honest. The winHTTP object contains various functions for sending/receiving data from winforms, but i dont think you can route this through a browser.

    The only real way I could think of to pass this information to the receiving website, is to build yourself an interim asp/asp.net page that receives a querystring, and builts a form that it automatically submits to the target site.
     
    Certifications: ITIL Foundation; MCTS: Visual Studio Team Foundation Server 2010, Administration
    WIP: None at present
  6. Fergal1982

    Fergal1982 Petabyte Poster

    4,196
    171
    211
    Ah. I didnt know that. but from the way I read it, that doesnt complete the issue. It sounds like Thomas wants to open a webpage of the target site, having posted it the information.
     
    Certifications: ITIL Foundation; MCTS: Visual Studio Team Foundation Server 2010, Administration
    WIP: None at present
  7. ThomasMc

    ThomasMc Gigabyte Poster

    1,507
    49
    111
    I've added a picture for a bit of visual rep

    i will try and outline the flow to see if that will help


    OP enters details from customer into form 1.
    When submit is clicked the information is sent to form 2, to be added to the hidden fields that i want to include and then encrypted, POSTED, and then loaded into a web browser(on form 2) as per the photo

    The OP then fills in the cc details in the browser on form 2, once that is done they are returned to success/failure page depending on the outcome.

    timer is checking the browser on form 2 for a code to say if it was completed or not and a reciept is printed of the transaction
     

    Attached Files:

    Certifications: MCDST|FtOCC
    WIP: MCSA(70-270|70-290|70-291)
  8. volatile

    volatile Nibble Poster

    60
    3
    19
    It sounds like what Matthew Tailor posted would work for you. As long know how the server on the other end will parse your POST data you should be good.
     
    Certifications: Computer Science Degree, A+
  9. dmarsh

    dmarsh Terabyte Poster

    3,782
    302
    184
    If you want to initiate the request from the browser instead of server side you generally need to alter the action URL of the form.

    I'd expect you need some combination of the form action and the submit.

    Code:
    <form method="Post" runat="server" action="your_cc_target_url" id="myform">
    
    ... Some stuff here ...
    
    <input type=submit runat=server> 
    
    ...
    
    Make sure the credit card page is accessed only with SSL for security, you also want to action post URL to be HTTPS also.

    If you are not posting to your own ASP .Net application you probably don't need the runat server attributes.
     
    Certifications: CITP, BSc, HND, SCJP, SCJD, SCWCD, SCBCD, SCEA, N+, Sec+, Proj+, Server+, Linux+, MCTS, MCPD, MCSA, MCITP, CCDH
  10. ThomasMc

    ThomasMc Gigabyte Poster

    1,507
    49
    111
    Sorry for not getting back lads, we got a new addition to the family and shes taking up most of my time right now. Once things slow down a little, I will be looking at this again.

    Thanks again.
     
    Certifications: MCDST|FtOCC
    WIP: MCSA(70-270|70-290|70-291)
  11. ThomasMc

    ThomasMc Gigabyte Poster

    1,507
    49
    111
    Thanks to everyone, I don't think i explained it to well but i managed to get the desired result with this.

    Code:
    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.WindowState = FormWindowState.Maximized
            Dim PostDataStr As String = "name=MyName&age=MyAge"
            Dim PostDataByte As Byte() = Encoding.UTF8.GetBytes(PostDataStr)
    
            Dim AdditionalHeaders As String = "Content-Type: application/x-www-form-urlencoded" + Environment.NewLine()
    
            WebBrowser1.Navigate("http://www.SomeURL.co.uk/test.php", "", PostDataByte, AdditionalHeaders)
    End Sub
    
     
    Certifications: MCDST|FtOCC
    WIP: MCSA(70-270|70-290|70-291)

Share This Page

Loading...