c# - 将 C# 字符串发送到 .PHP 页面

标签 c# php mysql

环顾四周后,我来到了 this page .在这里,我找到了一些将 C# 字符串发送到 PHP 页面的代码。

但是,在我自己的程序中实现后,它并没有起作用。这是我的代码:

        private void executesend()
        {  
            using (WebClient client = new WebClient())
            {
                client.UploadString(url,"POST",keys);
            }
        }

对于 PHP 部分,我有:

    <?php 
    mysql_connect("localhost", "", "") or die(mysql_error()); // Connect to database server(localhost) with username and password.
            mysql_select_db("dimittv89_dayz") or die(mysql_error()); // Select registration database.
            $name = $_GET["message"];
 if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
    $name = file_get_contents('php://input');

    $opdracht = "INSERT INTO 'keys', (`key`) VALUES ('$name')";
    print $name;
}

if (mysql_query($opdracht)){ 
echo "succesfully registerd to the melloniax u wil now be returned to our main page";
 }
 else{
 echo "hey something went wrong there ! please try again in a minute";
 }


 ?>

在同一主题中,一位用户也说要试试这个:

php?fmessage=testtesttest"

并使用

记下输出
$name = $_GET["message"];
print $name;

这也没有用。我做错了什么吗?

谢谢你的帮助

到目前为止,我发现错误的不是发送值,而是获取值:

Username = Registry.CurrentUser.OpenSubKey("Username", true);
Name = "" + Username.GetValue("Uid");

在 regedit 菜单中,它表示该值为 REG_BINARY,这些是否可通过 getvalue 读取?

最佳答案

将此代码用于 c# 和 php:

private void executesend()
    {  

                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

                req.Method = "POST";
                string Data = "message="+keys;
                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 
    mysql_connect("localhost", "", "") or die(mysql_error()); // Connect to database server(localhost) with username and password.
            mysql_select_db("dimittv89_dayz") or die(mysql_error()); // Select registration database.

 if (isset($_POST['message']))
{
    $name = $_POST['message'];

    $opdracht = "INSERT INTO keys (key) VALUES ('$name')";
    print $name;
    if (mysql_query($opdracht)){ 
     echo "succesfully registerd to the melloniax u wil now be returned to our main page";
    }
    else{
     echo "hey something went wrong there ! please try`enter code here` again in a minute";
    }

}

?>

关于c# - 将 C# 字符串发送到 .PHP 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14649007/

相关文章:

c# - Twig 算法

php - 为什么在通过 PhpUnit 运行测试时找不到我的自定义 TestCase 类?

PHP PDO 插入 MySQL 错误 SQL 语法

javascript - 在 CodeIgniter 中允许 URL 中的任何字符

javascript - 如何在刷新时显示来自 PHP 表单的随机文本和图像?

c# - 在 Global.asax 中验证 HTTP 请求和返回特定 HTTP 响应的正确方法是什么?

c# - 是否有可能让 c# 使用大多数特定类型而不是基类型的方法重载?

c# - 在 mac/win 上以编程方式访问 chrome 和 firefox 密码?

mysql - Laravel 代客 Linux : Can't connect MariaDB/Mysql

mysql - 在 MySQL 中创建 Single Blob 列来保存 BSON 是否符合 Mongo DB 数据库的目的?