-
Aug 19th, 2011, 01:11 PM
#1
Thread Starter
Junior Member
Send POST Method to a PHP file through Visual Basic
This is a function I did that will allow you to send data to a PHP file via the POST method...
Code:
Public Function PHP(ByVal url As String, ByVal method As String, ByVal data As String)
Try
Dim request As System.Net.WebRequest = System.Net.WebRequest.Create(url)
request.Method = method
Dim postData = data
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = byteArray.Length
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim response As WebResponse = request.GetResponse()
dataStream = response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
reader.Close()
dataStream.Close()
response.Close()
Return (responseFromServer)
Catch ex As Exception
Dim error1 As String = ErrorToString()
If error1 = "Invalid URI: The format of the URI could not be determined." Then
MsgBox("ERROR! Must have HTTP:// before the URL.")
Else
MsgBox(error1)
End If
Return ("ERROR")
End Try
End Function
Uses:
Code:
Dim htmlcode As String = PHP("http://somesite.com/somephpfile.php", "POST", "name=Jim&age=27&pizza=suasage")
Then you could have a PHP file that has something like
<?PHP
echo $_POST["name"] . " is " $_POST["age"] . " and he likes " . $_POST["pizza"] . " pizza. ";
?>
?>
-
Feb 19th, 2013, 11:16 AM
#2
New Member
Re: Send POST Method to a PHP file through Visual Basic
This is very useful. I was working a lot on MySQL database, which was on localhost, and then got shocked after figuring out that there is no way to connect to remote MySQL server. This solution saved my day (or week), even though there will be some extra work. Thanks a lot!
-
Feb 21st, 2013, 10:03 PM
#3
Fanatic Member
Re: Send POST Method to a PHP file through Visual Basic
Hi,
awesome post thanx,
FlashDark - there is most definately ways to connect to MySQL, the main one, you need to get the MySQL connector net: http://dev.mysql.com/downloads/connector/net/
My CodeBank Submissions
- Listbox with transparency and picture support - Click Here
- Check for a true internet connection - Click Here
- Open Cash drawer connected to receipt printer - Click Here
- Custom color and size border around form - Click Here
- Upload file to website without user logins, includes PHP - Click Here
- List All Removable USB Storage Devices - Click Here
- Custom On/Off Slide Control - Click Here
- Insert multiple rows of data into one database table using parameters - Click Here
- Trigger USB/Serial Cash Drawer - Click Here
-
Feb 21st, 2013, 10:52 PM
#4
Re: Send POST Method to a PHP file through Visual Basic
Originally Posted by FlashDark
This is very useful. I was working a lot on MySQL database, which was on localhost, and then got shocked after figuring out that there is no way to connect to remote MySQL server. This solution saved my day (or week), even though there will be some extra work. Thanks a lot!
Originally Posted by bensonsearch
It depends on where that remote database is located... I have a couple MySQL databases that are hosted, but I cannot access them remotely... I can only access them from within my host's domain... specifically either through the cpanel or from my webpages... so if I want to access the data outside of the firewall, I'd have to develop a web service of some kind that would then allow me access.
-tg
-
Feb 21st, 2013, 11:06 PM
#5
Fanatic Member
Re: Send POST Method to a PHP file through Visual Basic
Hi techgnome,
thats interesting, I found that issue but used the hosted cpanel to allow remote connections to the server from specific IP address's. I guess it all comes down to setup
My CodeBank Submissions
- Listbox with transparency and picture support - Click Here
- Check for a true internet connection - Click Here
- Open Cash drawer connected to receipt printer - Click Here
- Custom color and size border around form - Click Here
- Upload file to website without user logins, includes PHP - Click Here
- List All Removable USB Storage Devices - Click Here
- Custom On/Off Slide Control - Click Here
- Insert multiple rows of data into one database table using parameters - Click Here
- Trigger USB/Serial Cash Drawer - Click Here
-
Feb 22nd, 2013, 04:28 AM
#6
New Member
Re: Send POST Method to a PHP file through Visual Basic
Originally Posted by bensonsearch
Hi techgnome,
thats interesting, I found that issue but used the hosted cpanel to allow remote connections to the server from specific IP address's. I guess it all comes down to setup
As techgnome said, some shared hosting providers just won't allow you to connect to MySQL remotely because of security reasons, as it's in my particular situation.
-
Feb 22nd, 2013, 08:13 AM
#7
Re: Send POST Method to a PHP file through Visual Basic
Originally Posted by bensonsearch
Hi techgnome,
thats interesting, I found that issue but used the hosted cpanel to allow remote connections to the server from specific IP address's. I guess it all comes down to setup
rule of thumb - when dealing with remote/hosted databases... always check the host first to see if it's possible and/or if something need to be configured. While some do offer a whitelist... it can sometimes be more of a hassle... if you're the only one accessing it, then it's not much of a problem (until your ISP decides to give you a new IP) ... but if you're planning on distributing the app, where multiple people will have access... then you have to add all of their IPs to the white list... and then if they ever change....oi!
Originally Posted by FlashDark
As techgnome said, some shared hosting providers just won't allow you to connect to MySQL remotely because of security reasons, as it's in my particular situation.
Yeah, that's the case for me too... it's amazing though, there are a number that are wide open... no white list, no black list, not firewall of any kind.
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|