【问题标题】:c# windows form - How to make add entry on website after click buttonc# windows form - 单击按钮后如何在网站上添加条目
【发布时间】:2021-06-05 14:45:00
【问题描述】:

您好,我正在为我的培训编程制作一个小应用程序。我是 1 天的学习者:D。

我想在我的论坛中发布生成器帖子。我创建了简单的生成器,现在我想从应用程序发布到网站。

http://localhost/web/newthread.php?fid=5 <-- Its link to post website

<input type="text" class="textbox" name="subject" size="40" maxlength="85" value="" tabindex="1"> Its  place for Title on website

<body contenteditable="true" dir="ltr" class=" placeholder"><p><br></p></body> <-- Its place for entry

<input type="submit" class="button" name="submit" value="Napisz wątek" tabindex="4" accesskey="s"> <-- Its button to post 

现在...

当我在我的应用程序中单击 Button5 时

 private void button5_Click(object sender, EventArgs e)
    {

    }

想要。

  1. 转到链接(链接到发布网站)

  2. 从“textBox1_tytul”windows 应用复制文本到网站上放置标题

  3. 将文本从“textBox1_output”窗口应用程序复制到 Place 以在网站上输入

  4. 点击按钮在网站上发帖

  5. 在我的 Windows 应用程序中显示警报“已添加条目”

    string message = "已添加条目";
    MessageBox.Show(消息);

我是初学者,我不知道怎么做...任何帮助,对不起我的英语

【问题讨论】:

    标签: c# windows forms web httprequest


    【解决方案1】:

    我认为您必须更好地使用类 HttpClient。 例如,我从
    https://zetcode.com/csharp/httpclient/ 复制一段代码 我的意思是您必须通过 HttpClient 发出 Http 请求。 我希望我能理解你的问题并帮助你

    using System;
    using System.Text;
    using System.Net.Http;
    using Newtonsoft.Json;
    
    var person = new Person("John Doe", "gardener");
    
    var json = JsonConvert.SerializeObject(person);
    var data = new StringContent(json, Encoding.UTF8, "application/json");
    
    var url = "https://httpbin.org/post";
    using var client = new HttpClient();
    
    var response = await client.PostAsync(url, data);
    
    string result = response.Content.ReadAsStringAsync().Result;
    Console.WriteLine(result);
    
    record Person(string Name, string Occupation);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-12
      • 1970-01-01
      • 2020-08-13
      • 2015-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多