I have a script retu开发者_StackOverflow社区rns a string:
http://example.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://example.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://example.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()
Using wc As New System.Net.WebClient()
MsgBox(wc.DownloadString(String.Format("http://example.com/script.php?q={0}", My.Settings.setq)))
End Using
精彩评论