doujiao4705 2014-10-10 03:34
浏览 89

使用PHP POST的VB.NET WebRequest

Hello I am having trouble sending the post variable to received in the PHP document in my server. I tried it with the GET and it works fine. But what I notice is the POST VARIABLE doesn't receive the content I am sending. This is my code and thank in advanced:

VB.NET WINFORM CODE

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']; 
?>
  • 写回答

1条回答 默认 最新

  • douyu7879 2015-09-15 17:36
    关注

    Changing the ContentType should do the trick.

    request.ContentType = "application/x-www-form-urlencoded"
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!