POST data to a PHP page from C# WinForm

前端 未结 1 1358
忘了有多久
忘了有多久 2020-12-13 16:34

I have a winForms NET3.5SP1 app, and want to POST data to a PHP page.

I\'m also going to be passing it as JSON, but wanted to get straight POST working first.

<
相关标签:
1条回答
  • 2020-12-13 17:16

    i believe you need to properly encode and send the actual post content. it looks like you're just serializing into JSON, which PHP doesn't know what to do with (ie, it won't set it as $_POST values)

    string postData = "firstName=" + HttpUtility.UrlEncode(p.firstName) +
                      "&lastName=" + HttpUtility.UrlEncode(p.lastName) +                    
                      "&email=" + HttpUtility.UrlEncode(p.email) +
                      "&deviceUUID=" + HttpUtility.UrlEncode(p.deviceUUID);
    byte[] byteArray = Encoding.ASCII.GetBytes(postData);
    // etc...
    

    this should get your $_POST variable in PHP set. later when you switch to JSON you could do something like:

    string postData = "json=" + HttpUtility.UrlEncode(serializer.Serialize(p) );
    

    and grab from PHP:

    $json_array = json_decode($_POST['json']);
    
    0 讨论(0)
提交回复
热议问题