June 22, 2009

Post Data to Server with VB6

Post Data to Server with VB6

This is a simple coding which tell about process open internet to post data to server. here writer use PHP as the server program.
with any modification the programmer can add the database like MYSQL to their program.


OK let me let you know

Click Here to complete download

add module
--------------------------------------------------------------------------------------------------------------
Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_OPEN_TYPE_PROXY = 3
Const INTERNET_FLAG_RELOAD = &H80000000
Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags
As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long,
ByVal dwFlags As Long, ByVal dwContext As Long) As Long


Public Function GetReplyFromUrl(ByVal sUrl As String) As String
Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long
'add HTTP Prefix protocol
sUrl = "http://" & sUrl
'Create a buffer for the file we're going to download
sBuffer = String(1024, vbNullChar)
'Create an internet connection
hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
'Open the url
hFile = InternetOpenUrl(hOpen, sUrl, vbNullString, ByVal 0&, 1, ByVal 0&)
'Read the first 1024 bytes of the file
InternetReadFile hFile, sBuffer, Len(sBuffer), Ret
'clean up
InternetCloseHandle hFile
InternetCloseHandle hOpen
'return to Caller
etReplyFromUrl = Left(sBuffer, InStr(1, sBuffer, vbNullChar))
End Function



Form1
--------------------------------------------------------------------------------------------------------------
Private Sub Command1_Click()
Dim strData As String
Dim hostname As String ' hostname eg.localhost
hostname = "localhost"
strData = hostname & "/get.php?" & "value="
strData = strData & Text1.Text
UrlSendingDataResponse = GetReplyFromUrl(strData)
Text2.Text = strData
Text3.Text = UrlSendingDataResponse
End Sub



get.php


in script get.php value of $fname will be create to .txt file with name value.txt

Click Here to complete download. Download and remove get.php and value.txt to folder htdocs or www.

I think is very simple and maybe any programmer have a good way how to post the data from vb6???





Try to Post

Result at server

No comments:

Post a Comment

Let's us sharing

Recent Comment

Grab This Widget