正如我在图 block 中所说的那样......这是我的所有代码 我的 PHP 脚本
<?php
$DGURL = $_POST["url"];
$DGUSER = $_POST["user"];
$DGPASS = $_POST["pass"];
function db_connect() {
$hostname = '127.0.0.1';
$db_user = 'root';
$db_password = '';
$db_name = 'hit';
$conn = mysql_connect ($hostname, $db_user, $db_password) or
die (mysql_error());
echo "Success.. Connected to MySQL...<br />";
mysql_select_db($db_name) or die(mysql_error());
echo "Success.. Connected to Database...<br /> ";
return $conn;
}
$conn = db_connect();
function insertData($DGURL, $DGUSER, $DGPASS) {
$requete = "INSERT INTO data SET
Url='".$DGURL."',
Username='".$DGUSER."',
Password='".$DGPASS."'";
mysql_query($requete) or die(mysql_error());
}
if(isset($_GET['DGURL']) && isset($_GET['DGUSER']) && isset($_GET['DGPASS'])) {
insertData($_GET['DGURL'], $_GET['DGUSER'], $_GET['DGPASS']);
}
?>
这是我的 C# 代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Net;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string URL = "http://localhost/test.php";
WebClient webClient = new WebClient();
NameValueCollection formData = new NameValueCollection();
formData["url"] = "url";
formData["user"] = "user";
formData["user"] = "pass";
byte[] responseBytes = webClient.UploadValues(URL, "POST", formData);
string responsefromserver = Encoding.UTF8.GetString(responseBytes);
Console.WriteLine(responsefromserver);
webClient.Dispose();
}
}
}
有人可以解释一下这一点并帮助我修复和完善脚本吗?请帮忙。 任何帮助都会非常有用:)
最佳答案
有用且简单的示例 here
将此代码放入表单加载、按钮单击等操作中
string URL = "http://www.softwareandfinance.com/PHP/portal_welcome.php";
WebClient webClient = new WebClient();
NameValueCollection formData = new NameValueCollection();
formData["username"] = "testuser";
formData["password"] = "mypassword";
byte[] responseBytes = webClient.UploadValues(URL, "POST", formData);
string responsefromserver = Encoding.UTF8.GetString(responseBytes);
Console.WriteLine(responsefromserver);
webClient.Dispose();
关于C# 发送 POST 到 PHP MYSQL 但没有收到任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19187589/