I have a script returns a string:
http://mysite.com/script.php
PHP script:
$data = $_GET['q'];
$query = "SELECT * FROM `table` WHERE ID = '$data'";
$result = mysql_query($query);
$num = mysql_num_rows($result);
print $num;
I want to connect this script with VB, using this code
Dim con As String
con = "http://mysite.com/script.php?q=" & My.Settings.setq
Dim request = HttpWebRequest.Create(con)
request.Method = "GET"
Dim response = request.GetResponse()
Using reader = New StreamReader(response.GetResponseStream())
msgbox(reader.ReadToEnd())
End Using
It is not working. How can i do that?
EDIT: I found solution
here
Dim uri As New Uri("http://site.com")
Dim data As String = "data"
If (uri.Scheme = uri.UriSchemeHttp) Then
Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
request.Method = WebRequestMethods.Http.Post
request.ContentLength = data.Length
request.ContentType = "application/x-www-form-urlencoded"
Dim writer As New StreamWriter(request.GetRequestStream())
writer.Write(data)
writer.Close()
Dim response As HttpWebResponse = request.GetResponse()
Dim reader As New StreamReader(response.GetResponseStream())
Dim tmp As String = reader.ReadToEnd()
response.Close()