1

I am writing GUI for some PHP code I've written. I'm getting errors about the POST being unsuccessful.

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

I've run the same exact file using a html page to post to the php and it works perfectly.

Here's the error:

Here is my php that ip variable should be posted to:

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

$results = array();

$results = getScore($ipaddress);

echo $results;

Once it has the ipaddress field correctly the other fields should work.

My thoughts are that the post is not posting to the "ipaddress" field on my php file.

If anyone can spot anything in the code? or has an alternative solution for posting to the php please let me know!

8
  • Generally speaking, if you mention you're getting an error, you should include the exact error message, and where this error message is coming from - is it a VB error? A php error? An apache error? browser error? Commented Jul 17, 2012 at 16:41
  • @MarcB Error has been updated. Its coming from the php. Commented Jul 17, 2012 at 17:30
  • undefined index means you're accessing an item in an array that doesn't exist, and the rest tell you what the undefined property is. You need to show the PHP code, not the VB code. Commented Jul 17, 2012 at 17:31
  • @MarcB the php code is not the problem. As I said, it works perfectly when i run it using the html page to post the data. the problem lies in the VB posting Commented Jul 17, 2012 at 17:35
  • The two things are still related. You could be making an incorrect assumption in your VB code. Commented Jul 17, 2012 at 17:37

2 Answers 2

0

A major problem looks to be that you're setting your form data in the following line, but never passing that data to your PHP calling routine.

The call should look something like this:

txtCall.Text = PHP(url, method, completeCall)
Sign up to request clarification or add additional context in comments.

1 Comment

I appreciate your answer. It makes sense, but the context is different. That was something I need displayed, but I'm not actually connecting to that site. The site where its linked is correct, and then the ip address is sent to be POST
0

Replace this

$_POST["ipaddress"];

with this

$_POST["ip"];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.