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";
 }


 ?>

同じトピックで、ユーザーの 1 人もこれを試すように言っています。

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 に答える