c# 提交json 到指定url

180it 2025-03-22 AM 83℃ 0条
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

class Program
{
    static async Task Main(string[] args)
    {
        var url = "https://www.xxxx.com/info/info-add-ok_soft.php";
        var data = new
        {
            title2 = "arduino",
            classid = "3",
            title = "标题",
            keywords = "关键词",
            description = "备注",
            text = "<p>xxx<br/></p><pre class=\"brush:cpp;toolbar:false\">内容</pre><p><br/></p>",
            state = "1"
        };

        var json = JsonConvert.SerializeObject(data);
        var content = new StringContent(json, Encoding.UTF8, "application/json");

        using (var client = new HttpClient())
        {
            var response = await client.PostAsync(url, content);
            var responseString = await response.Content.ReadAsStringAsync();

            Console.WriteLine(responseString);
        }
    }
}
支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

c# 提交json 到指定url