Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将POST请求发送到默认浏览器中的自定义URI_C#_.net_Post_Httpwebrequest - Fatal编程技术网

C# 将POST请求发送到默认浏览器中的自定义URI

C# 将POST请求发送到默认浏览器中的自定义URI,c#,.net,post,httpwebrequest,C#,.net,Post,Httpwebrequest,我需要打开系统默认浏览器并发送一些自定义URI POST数据。所以我有两部分代码:第一部分-打开def浏览器,另一部分必须向其发送POST数据,但不发送 你能说些什么 enter code here private void button1_Click(object sender, EventArgs e) { string browser = string.Empty; RegistryKey key = null; try

我需要打开系统默认浏览器并发送一些自定义URI POST数据。所以我有两部分代码:第一部分-打开def浏览器,另一部分必须向其发送POST数据,但不发送

你能说些什么

enter code here private void button1_Click(object sender, EventArgs e)
    {

        string browser = string.Empty;
        RegistryKey key = null;
        try
        {
            key = Registry.ClassesRoot.OpenSubKey(@"HTTP\shell\open\command", false);

            //trim off quotes
            browser = key.GetValue(null).ToString().ToLower().Replace("\", "");
            if (!browser.EndsWith("exe"))
            {
                //get rid of everything after the ".exe"
                browser = browser.Substring(0, browser.LastIndexOf(".exe")+4);
            }
        }
        finally
        {
            if (key != null) key.Close();
        }
        //open default system browser
        System.Diagnostics.Process.Start(browser, strURL.Text);
//***************************************************

        // Convert string data into byte array 
        string strData = "Name=Sergiy&Age=21";
        byte[] dataByte = Encoding.UTF8.GetBytes(strData);

        HttpWebRequest POSTRequest = (HttpWebRequest)WebRequest.Create(strURL.Text);
        POSTRequest.Method = "POST";
        // Set the content type - Mine was xml.
        POSTRequest.ContentType = "application/x-www-form-urlencoded";
        POSTRequest.KeepAlive = false;
        POSTRequest.Timeout = 5000;
        POSTRequest.ContentLength = dataByte.Length;
        // Get the request stream
        Stream POSTstream = POSTRequest.GetRequestStream();
        // Write the data bytes in the request stream
        POSTstream.Write(dataByte, 0, dataByte.Length);

        //Get response from server
        HttpWebResponse POSTResponse = (HttpWebResponse)POSTRequest.GetResponse();

    }

我认为您对浏览器的唯一控制是它打开的URL。你也许能通过考试file://some/path URL,其中包含要作为javascript运行的代码。浏览器将启动,转到指定的文件://,在文件中运行javascript,然后post的结果将显示在浏览器中