使用 VisualBasic POST 到 PHP? [英] POST to PHP using VisualBasic?
问题描述
我正在为我编写的一些 PHP 代码编写 GUI.我收到有关 POST 不成功的错误消息.
I am writing GUI for some PHP code I've written. I'm getting errors about the POST being unsuccessful.
我从一个在线示例中获取了 PHP 函数代码,当它编译和运行时,它对我不起作用,因为我收到关于帖子不起作用的错误.
I took the PHP function code from an online example, and while it compiles and runs, it does not work for me in that I get errors about the post not working.
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,并且运行良好.
I've run the same exact file using a html page to post to the php and it works perfectly.
错误如下:
这是我的 php,ip 变量应该发布到:
Here is my php that ip variable should be posted to:
require("IPQFunctionworkingversionVXML.php");
$ipaddress = $_POST["ipaddress"];
$results = array();
$results = getScore($ipaddress);
echo $results;
一旦它具有正确的 ipaddress 字段,其他字段应该可以工作.
Once it has the ipaddress field correctly the other fields should work.
我的想法是该帖子没有发布到我的 php 文件中的ipaddress"字段.
My thoughts are that the post is not posting to the "ipaddress" field on my php file.
是否有人可以在代码中发现任何内容?或者有发布到 php 的替代解决方案,请告诉我!
If anyone can spot anything in the code? or has an alternative solution for posting to the php please let me know!
推荐答案
替换这个
$_POST["ipaddress"];
有了这个
$_POST["ip"];
这篇关于使用 VisualBasic POST 到 PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!