4

わかりましたので、作成した ac# コンソール ソース コードがありますが、思い通りに動作しません。

ブラウザーに入力する場合と同じように、データを URL に投稿する必要があります。

url with data = localhost/test.php?DGURL=DGURL&DGUSER=DGUSER&DGPASS=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["DGURL"] = "DGURL";
        formData["DGUSER"] = "DGUSER";
        formData["DGPASS"] = "DGPASS";

        byte[] responseBytes = webClient.UploadValues(URL, "POST", formData);
        string responsefromserver = Encoding.UTF8.GetString(responseBytes);
        Console.WriteLine(responsefromserver);
        webClient.Dispose();
    }
  }
}

私はまた、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 URI = "http://localhost/test.php";
            string myParameters = "DGURL=value1&DGUSER=value2&DGPASS=value3";

            using (WebClient wc = new WebClient())
            {
                wc.Headers[HttpRequestHeader.ContentType] = "text/html";
                string HtmlResult = wc.UploadString(URI, myParameters);
                System.Threading.Thread.Sleep(500000000);
            }
        }
    }
}

私は何日もの間、私のC#コンソールでこれを行う方法を見つけようとしています

4

2 に答える 2

0

C# で WebClient を使用して URL にデータを投稿する方法: https://stackoverflow.com/a/5401597/2832321

また、パラメーターを投稿しても、パラメーターは URL に表示されないことに注意してください。参照: https://stackoverflow.com/a/3477374/2832321

于 2013-10-04T20:24:27.677 に答える