2

环顾四周后,我来到了这个页面。在这里,我找到了一些将 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 读取吗?

4

1 回答 1

6

将此代码用于 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";
    }

}

?>
于 2013-03-28T10:15:54.493 回答