0

正如我在瓷砖中所说的......这是我所有的代码 MY PHP SCRIPT

<?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();
    }
  }
}

有人可以对此有所了解并帮助我修复和完善脚本,请帮助。任何帮助都会非常有用:)

4

1 回答 1

0

有用且简单的示例在这里

将此代码放入表单加载、按钮单击等操作中

     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();
于 2017-09-21T20:33:56.647 回答