看了一下后,我来到了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读取?
答案 0 :(得分: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";
}
}
?>