Library tutorials & articles

POSTing Form Data to a Web Page

Introduction

Being able to post data to a web page from within a Visual Basic application can be quite handy. Even better when you can 'see' the response and process it automatically. Fortunately, there are at least two different techniques to achieve this goal. The best one depends on the environment in which your application will be deployed, as well as the kind of posting that you want to do. We'll start with the easiest approach and then move on to the more flexible solution.

Comments

  1. 02 Jun 2007 at 23:14

    I am trying to post text data from my vb application to a web page field.how can i do this through simple asp code?help me

     

  2. 17 May 2006 at 22:45
    The easiest way to do this is by using the WebRobot component available at http://foxtrot-xray.com/web-robot/

    This component handles normal forms, multipart forms, cookies, redirection, proxies, automatically for you, and makes development so much simpler. You can even upload files using this component.



  3. 26 Jan 2006 at 00:13
    Hello...

    I have specific problem with ASP.NET server...

    I have writen code in Delphi with WinInet - which collect binary data togehther with MultiPart Form variables and send them on to ASP.NET server... Form is received, but ASP.NET can not recognize it...

    Begin of data look as this:

    Content-Type: multipart/form-data; boundary=---------------------------7d63b9261906a2
    Cookie: ASP.NET_SessionId=wyc1qgbe0bjkpmnv2eyn0m55; path=/
    Content-Length: 924855

    ---------------------------7d63b9261906a2
    Content-Disposition: form-data; name="Action"

    New
    ---------------------------7d63b9261906a2
    Content-Disposition: form-data; name="SMAPIAction"

    FileUpload
    ---------------------------7d63b9261906a2
    Content-Disposition: form-data; name="DraftID"

    2C8C0EAD63B24D4492403BDF908DA67B
    ---------------------------7d63b9261906a2
    Content-Disposition: form-data; name="file_0"; filename="C:\ROK-PLAYER.zip"
    Content-Type: application/octet-string

    PK...........

    When I post these data to classic CGI under IIS, form data are recognized OK...
    When I post them to ASP.NET server - problem continue...

    I have set Content-Length of course...

    Do you know some settings which can help me with posting data to ASP.NET server, please?

    Thank you for responses...
  4. 25 Jan 2006 at 14:22
    I'm also looking for a solution to this problem.  Has anyone else any answers?  My problem being if you post back a string which contains an & - then what happens?

    Thanks,

    Chris
  5. 14 Dec 2005 at 10:51

    you have only to activate "microsoft xml 4.0" or "microsofr XML 5.0" and clik OK

  6. 20 Oct 2005 at 03:21

    I'm having the same problem, I'm trying to do the POST and redirect to PayPal site at the same time but the page is shown in my server.


    Thanks in advance.


    Luciano

  7. 23 Sep 2005 at 16:13

    I tried to get something out of the POST method by


    Text1.Text = xmlhttp.ReponseText


    but it says object's property/method not supported. also i can't find the ServerXMLHTTP class for MSXML2 in my libraries.. can anyone please tell me what is wrong with it..

  8. 19 Sep 2005 at 20:41

    musalpay,


    Yes it works for me now.  Perhaps if you explain what isn't working, others can help.


    -jack

  9. 18 Sep 2005 at 06:30

    Quote:
    [1]Posted by jsuzuki on 21 Jan 2005 08:53 AM[/1]
    Excellent summary on how to POST content to a webserver.


    I do have comment on the method that uses the ServerXMLHTTP.  In the line

    Code:
    xmlhttp.send "Id=1&S=2"

    I would change it to something like
    Code:
    dim PostStr as String: PostStr = "Id=1&S=2"
    xmlhttp.send (PostStr)


    Notice the parentheses around the variable PostStr.  Without it, 0-byte length content is sent.  Caused me a bit of grief as I tried to figure this out.  Hopefully this comment will save others some time.



    Are you solve the problem. It does not work. I dont understand why.

  10. 15 Sep 2005 at 07:36

    Has anyone been able to find the solution of the above problem?
    if you have found the solution Bardyl , please email me at someone_chuss@yahoo.ca

  11. 04 Jul 2005 at 11:35

    How to  programmatically send in Asp.Net  a classic "multipart/form-data" form to a server?


    Hi everyone ,


    I've been searching for hours about a common Internet programming question and I'm certainly not the only one having the following problem :



    With .Net (be it Delphi or VB), I need to POST a form to a .php server. If I pass the following parameter to the request :
    objRequest.ContentType := 'application/x-www-form-urlencoded';


    everything works fine. Except that if I need to transmit special characters from the form - like for example french or german accents - those laters are not transmitted in the format waited by the server (ISO-8859-1). So when you send text to the server via this form, you get unreadable or not corresponding character on the server side. Changing the content type like this on the *.aspx form source code doesn't change anything :


    objRequest.ContentType := 'application/x-www-form-urlencoded; charset=ISO-8859-1';


    No more result if you modify the web.config by adding the following line :


    <globalization requestEncoding="ISO-8859-1" responseEncoding="ISO-8859-1" />


    Another solution I tried was to HTML encrypt the parameter string posted back to server with the following .Net method :


    FormString := HttpUtility.HtmlDecode(FormString);


    No way. It makes new problem because of the "&" parameter separator... If you have special characters, it adds "&" in the string. For example the e-cute accent (é) is converted into é HTML code and the #233; is then considered as a parameter...


    Some peolpe say that the content type "application/x-www-form-urlencoded" should not be used when you post a form. (there is also confusion between POST and GET method because usually you don't POST form be sending parameters into URL but this is another question). And I've remarked that actually, even if the server also accepts "application/x-www-form-urlencoded" form (certainly for compatibility reason), it is actually waiting for a "multipart/form-data" form. Posting form in "multipart/form-data" is also recommended by many people.


    So, here is my question : how in Asp.Net  to send programmatically to a server a classic "multipart/form-data" form containing characters of type ISO-8859-1 ? What must be the syntax of the string containing the content of the form and the request parameters ? With "application/x-www-form-urlencoded" form, the form parameter string is simple a line such as "parameter1=abc&parameter2=def". It doesn't work with "multipart/form-data" that encapsulate parameters between bounadaries. I found the following syntax exampe at http://www.faqs.org/rfcs/rfc2388.html but I don't succeed in applying it to my application :


       --AaB03x
       content-disposition: form-data; name="parameter1"
       content-type: text/plain;charset=ISO-8859-1
       content-transfer-encoding: quoted-printable


       abc
       --AaB03x--AaB03x
       content-disposition: form-data; name="parameter2"
       content-type: text/plain;charset=ISO-8859-1
       content-transfer-encoding: quoted-printable


       def
       --AaB03x



    There are plenty of information and examples about using the "multipart/form-data" form to upload file on a server but I couldn't find any about simply sending a classic form including text fields with special characters like accents. If one knows how to do that, it would be great if one could put a short example onto your site ! I think it could be very usefull for a lot of people !


    Thanks a lot for your precious attention!


    Laurent,
    Switzerland






  12. 02 Jun 2005 at 06:01
    Hello,

    I would like o use ServerXMLHTTP to POST data to a remote server and to also be redirected to that same page as if I am in a client browser and I clicked on the submit button of a form.  I don't know how to get ServerXMLHTTP to follow the POST when I send it.

    I understand that it returns a responseText object but when I write it out it displays a normal looking page but I am still sitting on my server rather than the server I tried POSTING too...

    I'm hoping there are some properties that I can set to do this...

    Any help would be much appreciated.

    Here is my code that I've been playing around with:

    <%@LANGUAGE="VBSCRIPT"%>
    Dim objHttp
    Dim str

    If Request.ServerVariables("Request_Method") = "POST" Then
       str = "cmd=_xclick&item_name=test&no_note=1¤cy_code=USD"

       'Declare OUR POST object
       Set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
       objHttp.Open "POST", "https://www.paypal.com/cgi-bin/webscr", FALSE
       objHttp.setRequestHeader "Host", "www.paypal.com"
       objHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
       objHttp.setRequestHeader "Content-Length", Len(str)
       objHttp.Send str

       Response.Write (objHttp.ResponseText)
    End If
    Set objHttp=nothing%>
  13. 09 Apr 2005 at 09:51

    How do i post data contains carriage return character i.e., text from TEXTAREA control.

  14. 25 Jan 2005 at 22:49

    Maybe I'm just blind, but I've read through the API method a few times, and I can't see where in all that code you put the URL. I can only find the path.

  15. 21 Jan 2005 at 08:53

    Excellent summary on how to POST content to a webserver.


    I do have comment on the method that uses the ServerXMLHTTP.  In the line

    Code:
    xmlhttp.send "Id=1&S=2"

    I would change it to something like
    Code:
    dim PostStr as String: PostStr = "Id=1&S=2"
    xmlhttp.send (PostStr)


    Notice the parentheses around the variable PostStr.  Without it, 0-byte length content is sent.  Caused me a bit of grief as I tried to figure this out.  Hopefully this comment will save others some time.

  16. 21 Sep 2004 at 15:01

    I am trying to get certain data from a GPS web page so that it can be transimitted to a microcontroller and later to a pda


    any sugestions on what language I should use.


  17. 12 Sep 2004 at 10:04

    Thanks for this code sample, but I tried the VB code suggested, but my ASP page continues to say that no form data has been sent. I call my ASP page and send 1 parameter, then in my ASP page, I respond with this:


    Response.CacheControl = "no-cache"
    Response.AddHeader "Pragma", "no-cache"
    Response.Expires = -1


    Response.Write "Form Parameters (Submit method=POST):"


    For each reqItem in Request.Form
      Response.Write reqItem & "=" & Request.Form(reqItem) & "<br>"    
    Next


    However, no Request.Form items are written. Am I missing something?


    Thanks!

  18. 17 May 2004 at 14:08
    How can this be done in C#? I tried to convert this solution and did not work.

    It seems the object was not created successfully. Can anyone help out in this?
  19. 30 Sep 2003 at 12:27
    I didn't look at the code yet, but I wrote a program that catches machine data (through WMI and API) and posts it to a web site form.  No browser opens up or anything, I only put a thank you message in the app to let the user know data has been sent.  The purpose of the program is to keep an inventory of users hardware, etc. so that I know when to upgrade browsers/mail accounts/ HD etc.  It writes to an access db that I look up.  I've gotten the program to work on some 98/2k/xp Pro.  Running the app on some 98 machines have had problems. If you want I can email you the whole package so that you can see how it works.  
  20. 17 Sep 2003 at 04:24

    Anyone got the sample?
    Also how to parse the data coming back from the POST ?

  21. 17 Sep 2003 at 04:22

    Guyz that was a wonderfull article, but now the other part is how do we process the data coming back as the response from the POST?

  22. 02 Jul 2003 at 06:09

    I wrote a very similar code using C++.  The posted data is handled in the same page as the form.  After posting the data, i get returned to the same page as though the data was not posted.  Any ideas?

  23. 29 Jun 2003 at 22:06

    I am trying to post my vb data to a web page field.  I have tried the code suggested with no success.


    I have pasted in the declarations to my form generalities section.  I created a command button and pasted the winlnet api code to the command button.  When I press the command button, the processor kicks up, but I see no results.  The web browser doesn't open and the desired web page never loads.  I am not receiving any errors.


    Have I missed something here.

  24. 18 Jun 2003 at 10:31
    Hello Bruce,

    Could you please send the sample to me also at  "paragm78@yahoo.com" ?
    I want to post form variables to a webpage from a VB application.

    Thanks.
    Parag.
  25. 14 Jun 2003 at 14:12

    He articulates it is very good, the topic of the spaces that disappear is a problem, but has solution.  
    What I cannot solve is the transmission of characters like" &","%", etc.  
     
    Front Page, uses a shipment form that converts to hexadecimal these characters before sending them.  
     
    As this it is made?

  26. 14 Apr 2003 at 18:18

    Sorry for the delay in responding.  There is a technique for doing this, but it is a little convoluted.  It involves using a multipart request. I'll try to put together an example on the topic in the next couple of days and post it to the site.


  27. 14 Apr 2003 at 18:13

    The string needs to be converted to its URL encoding. You can find a routine to do this at http://www.tagconsulting.com/Show.asp?Id=1027.

  28. 14 Apr 2003 at 16:55

    You need to "escape" the line you are sending.  You basically convert all non alpanumeric characters to their hex code equivalent.  For example a space should be %20.  Your line should be "Address=1%20Main%20Street".


    There is a function in javascript that does this (escape and unescape).  There are various routines for doing this in VB that I can point you to.  Just let me know.


    I agree.  This article is excellent.  Excatly what I was looking for!!  


    Brian


    Quote:
    [1]Posted by dgrenader on 3 Apr 2003 05:39 PM[/1]
    Great article! All works, except when I send a FORM field with white space it disappears.


    So when objXMLHTTP.Send reqStr "Address=1 Main Street" is processed by the server, I get "1MainStreet" with white-space gone.


    What am I doing wrong? Thanks!

  29. 03 Apr 2003 at 17:39
    Great article! All works, except when I send a FORM field with white space it disappears.

    So when objXMLHTTP.Send reqStr "Address=1 Main Street" is processed by the server, I get "1MainStreet" with white-space gone.

    What am I doing wrong? Thanks!
  30. 10 Mar 2003 at 07:11

    I'm having trouble implementing the <INPUT Type=file> posting method.
    I implemented the first method easy, but when i tried the second it just doesn't work and i cant seem to find any help anyware about the subject.
    Can you help me? I'm almost out of ideas.
    Can you post the code of TestPost.asp page, so that i can see what in the hell am i doing wrong?


    Thanks in advance!


    EDIT: I removed the HTML Syntax from the subject line that was causing a few issues on the main page...

  31. 26 Feb 2003 at 17:00

    I actually do have a sample project that does this.  Send me you're email address and I'll send it along.

  32. 03 Feb 2003 at 05:57
    This means that, if I have the same fields in a VB form, I can 'transfer' it into a HTML page?

    Is there any working sample that I can download?

    Well, it's brilliant...
  33. 01 Jan 1999 at 00:00

    This thread is for discussions of POSTing Form Data to a Web Page.

Leave a comment

Sign in or Join us (it's free).

Bruce Johnson I am the owner of a small application development consulting company that specialized in the design and implementation of Internet-based applications. While there are others who can make a web site...

Related discussion

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

We'd love to hear what you think! Submit ideas or give us feedback