C# 将字符串发送到PHP页面并让PHP页面显示该字符串
我要做的是让我的PHP页面显示一个字符串,这个字符串是我通过System.Net.WebClient在C#应用程序中的函数创建的 就是这样。以最简单的形式,我有: WebClient client = new WebClient(); string URL = "http://wwww.blah.com/page.php"; string TestData = "wooooo! test!!"; byte[] SendData = client.UploadString(URL, "POST", TestData); WebClient客户端=新的WebClient(); 字符串URL=”http://wwww.blah.com/page.php"; string TestData=“wooooo!test!!”; 字节[]SendData=client.UploadString(URL,“POST”,TestData); 所以,我甚至不确定这样做是否正确。。我不确定如何实际获取该字符串并将其显示在PHP页面上。像打印(发送数据)之类的东西C# 将字符串发送到PHP页面并让PHP页面显示该字符串,c#,php,webclient,C#,Php,Webclient,我要做的是让我的PHP页面显示一个字符串,这个字符串是我通过System.Net.WebClient在C#应用程序中的函数创建的 就是这样。以最简单的形式,我有: WebClient client = new WebClient(); string URL = "http://wwww.blah.com/page.php"; string TestData = "wooooo! test!!"; byte[] SendData = client.UploadString(URL, "POS
任何帮助都将不胜感激 过账分为两半。1) 发布到页面的代码和2)接收该页面的页面 表1) 你的C#看起来不错。我个人会使用:
string url = "http://wwww.blah.com/page.php";
string data = "wooooo! test!!";
using(WebClient client = new WebClient()) {
client.UploadString(url, data);
}
第2页)
在PHP页面中:
if ( $_SERVER['REQUEST_METHOD'] === 'POST' )
{
$postData = file_get_contents('php://input');
print $postData;
}
在此处阅读有关在PHP中读取post数据的内容:
try
{
string url = "";
string str = "test";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
string Data = "message="+str;
byte[] postBytes = Encoding.ASCII.GetBytes(Data);
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = postBytes.Length;
Stream requestStream = req.GetRequestStream();
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
Stream resStream = response.GetResponseStream();
var sr = new StreamReader(response.GetResponseStream());
string responseText = sr.ReadToEnd();
}
catch (WebException)
{
MessageBox.Show("Please Check Your Internet Connection");
}
和php页面
<?php
if (isset($_POST['message']))
{
$msg = $_POST['message'];
echo $msg;
}
?>
如果您可以控制php页面,则可以将TestData作为url中的querystring参数发送。。。然后在php页面中,您将使用它。这可能的重复没有什么意义。这个C#应用程序在哪里运行?您希望它向一个PHP页面发送一个字符串,然后在同一页面上显示该字符串?在另一页上?显示到哪个浏览器?我知道这很可笑。但是——是的;我希望C#应用程序将字符串发送到一个完全不同的服务器(我可以访问该服务器)上的PHP页面,在那里我可以在以后进一步操作该字符串(从中提取内容,将提取的数据放入数据库等)。它被称为web服务;)非常感谢。我得到了C#代码,但在PHP代码中,我仍然无法在收到字符串后在页面上显示它。。可能是我犯了一个愚蠢的错误,但它让我发疯了:((得到一个空白页)然后我会先尝试通过查询字符串发送数据,看看你是否能做到这一点(例如,使用c#将数据发送到!!然后使用php print$\u get[“fmessage”];)一旦你成功了,我会回到帖子上来。谢谢你,伙计。我也需要这个。