1

我正在为我编写的一些 PHP 代码编写 GUI。我收到关于 POST 不成功的错误。

我从一个在线示例中获取了 PHP 函数代码,当它编译和运行时,它对我不起作用,因为我收到关于帖子不起作用的错误。

Imports System.Text
Imports System.IO
Imports System.Net

Public Class Form1

    Private Sub btnIP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIP.Click
        Dim ip, firstBit, secondBit, completeCall As String

        firstBit = "apikey=eb4a84&method=risk&ip="
        secondBit = "&categories=&options=url_detail"
        ip = txtIP.Text

        completeCall = firstBit + ip + secondBit

        txtCall.Text = completeCall

        Dim url, method As String

        method = "POST"
        url = "http://localhost/myfiles/WorkingVersionVQuickLookXML.php"




        txtCall.Text = PHP(url, method, ip)


    End Sub

    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
End Class

我已经使用 html 页面运行相同的文件以发布到 php 并且它运行良好。

这是错误:

这是我的 php,应该将 ip 变量发布到:

require("IPQFunctionworkingversionVXML.php");
$ipaddress = $_POST["ipaddress"];

$results = array();

$results = getScore($ipaddress);

echo $results;

一旦它具有正确的 ipaddress 字段,其他字段应该可以工作。

我的想法是该帖子没有发布到我的 php 文件中的“ipaddress”字段。

如果有人能在代码中发现任何东西?或有发布到 php 的替代解决方案,请告诉我!

4

2 回答 2

0

替换这个

$_POST["ipaddress"];

有了这个

$_POST["ip"];
于 2012-07-18T18:50:15.450 回答
0

一个主要问题似乎是您在以下行中设置表单数据,但从未将该数据传递给您的 PHP 调用例程。

调用应如下所示:

txtCall.Text = PHP(url, method, completeCall)
于 2012-07-17T17:48:34.900 回答