title: POST to PHP using VisualBasic?
body: <p>I am writing GUI for some PHP code I've written. I'm getting errors about the POST being unsuccessful.</p>
  
  <p>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.</p>
  
  <pre><code>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&amp;method=risk&amp;ip="
          secondBit = "&amp;categories=&amp;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
  </code></pre>
  
  <p>I've run the same exact file using a html page to post to the php and it works perfectly.</p>
  
  <p>Here's the error:</p>
  
  <p>Here is my php that ip variable should be posted to:</p>
  
  <pre><code>require("IPQFunctionworkingversionVXML.php");
  $ipaddress = $_POST["ipaddress"];
  
  $results = array();
  
  $results = getScore($ipaddress);
  
  echo $results;
  </code></pre>
  
  <p>Once it has the ipaddress field correctly the other fields should work. </p>
  
  <p>My thoughts are that the post is not posting to the "ipaddress" field on my php file.</p>
  
  <p>If anyone can spot anything in the code? or has an alternative solution for posting to the php please let  me know!</p>