0

我有一个脚本返回一个字符串:

http://example.com/script.php

PHP 脚本:

$data = $_GET['q'];

$query = "SELECT * FROM `table` WHERE ID = '$data'";
$result = mysql_query($query);
$num = mysql_num_rows($result);

print $num;

我想将此脚本与 VB 连接,使用此代码

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

它不工作。我怎样才能做到这一点?

编辑:我找到了解决方案

这里

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()
4

1 回答 1

0
Using wc As New System.Net.WebClient()
    MsgBox(wc.DownloadString(String.Format("http://example.com/script.php?q={0}", My.Settings.setq)))
End Using
于 2012-05-08T19:50:40.673 回答