VB.NET WebRequest with PHP POST
Hello I am having trouble sending the post variable I received in a PHP document on my server. I tried it with GET and it works great. But I notice that the POST VARIABLE is not receiving the content I am posting. This is my code and thanks in advanced:
WINFORM CODE VB.NET
enter code here
Dim Username = TxtUser.Text
Dim PostData = "user_name=" & Username
Dim request As WebRequest = WebRequest.Create("http://website.com/test.php")
request.Method = "POST"
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(PostData)
request.ContentType = "application/x-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()
MsgBox(responseFromServer)
PHP CODE
<?php
//I tried this $user_name= 'SOMETHING'; and works fine.
$user_name= $_POST['user_name'];
?>
+3
source to share