我正在爲我寫的一些PHP代碼編寫GUI。我收到有關POST失敗的錯誤。使用VisualBasic POST到PHP?
我從一個在線示例中獲取了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知識產權的變量應張貼於:
require("IPQFunctionworkingversionVXML.php");
$ipaddress = $_POST["ipaddress"];
$results = array();
$results = getScore($ipaddress);
echo $results;
一旦有ip地址字段正確其他字段應該工作。
我的想法是,這篇文章沒有發佈到我的php文件的「ipaddress」字段。
如果任何人都可以在代碼中發現任何東西?或者有一個替代解決方案張貼到PHP請讓我知道!
一般來說,如果你提到你得到一個錯誤,你應該包含確切的錯誤信息,以及這個錯誤信息來自哪裏 - 是VB錯誤嗎?一個PHP錯誤? apache錯誤?瀏覽器錯誤? – 2012-07-17 16:41:41
@MarcB錯誤已更新。它來自PHP。 – GK1667 2012-07-17 17:30:16
未定義的索引意味着您正在訪問不存在的數組中的項目,其餘部分會告訴您未定義的屬性是什麼。您需要顯示PHP代碼,而不是VB代碼。 – 2012-07-17 17:31:24