Sending a string to a PHP page and having the PHP Page Display The String

后端 未结 2 569
广开言路
广开言路 2021-01-23 05:03

What I\'m trying to do is have my PHP page display a string that I\'ve created through a function in my C# application, via System.Net.WebClient.

That\'s really it. In i

2条回答
  •  时光说笑
    2021-01-23 05:18

    There are two halves to posting. 1) The code that posts to a page and 2) the page that receives it.

    For 1) Your C# looks ok. I personally would use:

    string url = "http://wwww.blah.com/page.php";
    string data = "wooooo! test!!";
    
    using(WebClient client = new WebClient()) {
        client.UploadString(url, data);  
    }
    

    For 2) In your PHP page:

    if ( $_SERVER['REQUEST_METHOD'] === 'POST' )
    {
        $postData = file_get_contents('php://input');
        print $postData;
    }
    

    Read about reading post data in PHP here:

    • http://us.php.net/manual/en/wrappers.php.php
    • http://php.net/manual/en/reserved.variables.httprawpostdata.php

提交回复
热议问题