将字符串发送到 PHP 页面并让 PHP 页面显示字符串 [英] Sending a string to a PHP page and having the PHP Page Display The String

查看:39
本文介绍了将字符串发送到 PHP 页面并让 PHP 页面显示字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是让我的 PHP 页面显示一个字符串,该字符串是我通过 C# 应用程序中的函数创建的,通过 System.Net.WebClient.

原来如此.以最简单的形式,我有:

<前>WebClient 客户端 = new WebClient();字符串 URL = "http://wwww.blah.com/page.php";string TestData = "wooooo! test!!";byte[] SendData = client.UploadString(URL, "POST", TestData);

所以,我什至不确定这是否是正确的方法……而且我不确定如何实际获取该字符串并将其显示在 PHP 页面上.像 print_r(SendData) ??

任何帮助将不胜感激!

解决方案

发帖分为两部分.1) 发布到页面的代码和 2) 接收它的页面.

对于 1)你的 C# 看起来不错.我个人会使用:

string url = "http://www.blah.com/page.php";string data = "wooooo! test!!";使用(WebClient客户端=新WebClient()){client.UploadString(url, data);}

对于 2)在您的 PHP 页面中:

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

在此处阅读有关在 PHP 中读取帖子数据的信息:

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 it' s simplest form, I have:

WebClient client = new WebClient();  
string URL = "http://wwww.blah.com/page.php";
string TestData = "wooooo! test!!";

byte[] SendData = client.UploadString(URL, "POST", TestData);

So, I'm not even sure if that's the right way to do it.. and I'm not sure how to actually OBTAIN that string and display it on the PHP page. something like print_r(SendData) ??

ANY help would be greatly appreciated!

解决方案

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:

这篇关于将字符串发送到 PHP 页面并让 PHP 页面显示字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆