Post to PHP

Posted on 2005-05-13
Last Modified: 2010-04-23
As simple as this: I want to post some data to my PHP form on the internet. At the moment I have it doing it through a webbrowser control, inputting the text into a form and artificially pressing the "submit" button. This doesn't seem to be very reliable, so what other, more reliable method should I use?

Thanks a lot :-). Let me know if you need clarification.
Question by:robert4532
    LVL 13

    Accepted Solution

    I assume you want to upload a file in a POST request, is that correct? Or do you just want to fill out some fields on a form? (would be easier)

    This is to upload a file: Is C# ok? it's easy to convert :) - if this is a problem, let me know.

    { FileStream objfilestream = new FileStream
    int len = (int)objfilestream.Length;
    Byte[] buffer = new Byte[len];
    // create the Http Request
    StringBuilder requestStream = new System.Text.StringBuilder();
    for(int i = 0; i < buffer.Length; i++)
    { requestStream.Append(string.Format("file={0}", buffer[i]
    ) + ((i < buffer.Length - 1 && buffer.Length > 1) ? "&" :
    UTF8Encoding encoding = new UTF8Encoding();
    byte[] requestStreambuffer = encoding.GetBytes(requestStream.ToString()
    HttpWebRequest httpRequest = (HttpWebRequest)
    httpRequest.Method = "POST";
    httpRequest.KeepAlive = true;
    httpRequest.ContentType = "application/x-www-form-urlencoded";
    httpRequest.ContentLength = requestStreambuffer.Length;
    httpRequest.Timeout = 30000;
    httpRequest.GetRequestStream().Write(requestStreambuffer, 0,
    requestStreambuffer.Length); httpRequest.GetRequestStream().Close();
    } catch(Exception exp) { Console.WriteLine(string.Format
    ("Error: {0}", exp.Message)); }

    Author Comment

    I just want to fill out some fields on a form, expect without actually filling them out manually (submitting directly to the page that process the post).


    Expert Comment

    Would it be possible to get the above solution in VB ? I'm really not familiar with C#.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now