Wrox Programmer Forums
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 18th, 2004, 01:28 AM
Authorized User
 
Join Date: Oct 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default Send form data using VB

i want to send form data by POST method using VB to one .php file.
data are username and password. Currently data send from html page now i want to send same from VB program. The HTML page also contains some javascript code.
 how can i do this, anyone knows please help me it is urgent for me.

Ratheesh

SW Programmer from INDIA
__________________
Tell me what you need and i will tell you how to get along without it.
-----------------------------------------------------------------
Ratheesh
Bangalore, INDIA
[email protected]
 
Old October 18th, 2004, 03:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can use the XMLHTTP object which comes with MSXML, (see http://support.microsoft.com/default.aspx?kbid=290591) or if you prefer an OCX, try the Internet Transfer Control.
 
Old October 18th, 2004, 03:58 AM
Authorized User
 
Join Date: Oct 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

but can u give any sample code to do that and, how i can do the javascript code in vb (that is in the html code)

SW Programmer from INDIA
 
Old October 18th, 2004, 05:24 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Surely its not that difficult to translate that little bit of js:
function XMLHTTPButton_onclick() {
    var DataToSend = "id=1";
    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.Open("POST","http://<%=Request.ServerVariables("Server_Name")%>/Receiver.asp",false);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send(DataToSend);
    alert(xmlhttp.responseXML.xml);
}

delete all trailing ;
var -> Dim
new ActiveXObject -> CreateObject
put Call in front of the next 3 lines
alert -> MsgBox

voila!
 
Old October 18th, 2004, 06:03 AM
Authorized User
 
Join Date: Oct 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

now the code i have tried is as follows but, it gives the statusText as 'Bad Request'. if print the responseXML.xml also it gives "". any problem in my code , please help

    Dim xmlhttp
    Set xmlhttp = New MSXML2.ServerXMLHTTP
    xmlhttp.Open "POST", "http://localhost:8080/logini.jsp", False
    xmlhttp.setRequestHeader "Content-Type", "application/x-www-form- urlencoded"
    xmlhttp.send DataToSend
    lblStatus.Caption = xmlhttp.statusText
    'lblStatus.Caption = xmlhttp.responseXML.xml
    Set xmlhttp = Nothing

i displayed the responseText it gives the following
================================================== ===
<base href="http://localhost:8080/logini.jsp">
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>

  <HEAD>
    <title>Bad Request (400)</title>
  </HEAD>

  <BODY BGCOLOR="#eeeeff">
    <IMG SRC="/system/images/banner.gif"
         ALT="Java Web Server from Sun Microsystems">
    <H1><IMG SRC="/system/images/Error_Duke.gif"
             ALIGN=TOP
             ALT="Duke's Error Image">
    Bad Request (400)</H1>

    Your request to the server could not be understood. Please check to
    ensure that the request you made is correct.

  </BODY>
</HTML>
================================================== ======

i think some error in the request

SW Programmer from INDIA
 
Old October 18th, 2004, 06:45 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

1. use the "XMLHTTP" object from VB, not the "ServerXMLHTTP" object
2. do you really have a space here "application/x-www-form- urlencoded"?
3. is there anything in "DataToSend" variable
4. have you looked at the webserver logs to see what the request looks like from that end? this may give additional clues.
 
Old October 18th, 2004, 07:05 AM
Authorized User
 
Join Date: Oct 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

1,2,3 points are ok
log file from server i copied here
the logini.jsp file just display "hai" in the the <body> of <html >

127.0.0.1 - - [18/Oct/2004:11:16:51 +0000] "POST /logini.jsp HTTP/1.1" 400 619
127.0.0.1 - - [18/Oct/2004:11:16:59 +0000] "POST /logini.jsp HTTP/1.1" 400 619
127.0.0.1 - - [18/Oct/2004:11:20:40 +0000] "POST /logini.jsp HTTP/1.0" 400 619
127.0.0.1 - - [18/Oct/2004:11:42:24 +0000] "POST /logini.jsp HTTP/1.0" 400 619
------------------------------------------------------------
127.0.0.1 - - [18/Oct/2004:11:52:55 +0000] "GET /logini.jsp HTTP/1.1" 200 84
127.0.0.1 - - [18/Oct/2004:11:54:57 +0000] "GET /logini.jsp HTTP/1.1" 304 101
127.0.0.1 - - [18/Oct/2004:11:54:58 +0000] "GET /logini.jsp HTTP/1.1" 304 101

first 4 requests are from my vb program and last 3 by using web browser. can u find out any problem


SW Programmer from INDIA
 
Old October 18th, 2004, 07:20 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Have you tried a GET instead of a POST? Are you actually POSTing anything?
 
Old October 18th, 2004, 07:29 AM
Authorized User
 
Join Date: Oct 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i am really sorry. by using GET i am getting the correct result.
can i send data by POST in the same way ie

dataToSend="login=" & txtUserName & "&passwd=" & txtPassword

this way i am sending data in GET method
is it work

Thanks for your valuable inforamtions......


SW Programmer from INDIA





Similar Threads
Thread Thread Starter Forum Replies Last Post
Send data using vb.net over a LAN. Hisham VB.NET 2002/2003 Basics 0 November 7th, 2004 04:29 PM
Send form data using VB ratheeshpkr Classic ASP XML 0 October 18th, 2004 01:19 AM
How to send form data without pressing SUBMIT eapsokha Classic ASP Professional 2 March 1st, 2004 09:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.