HTTP GET 不能通过 Body 来发送数据呢?

目前不确定,以下代码只为记录,有兴趣的同学,可以试试

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

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

        private void button1_Click(object sender, EventArgs e)
        {
            var client = new RestClient("https://qrcode-webapi-uat.chinacloudsites.cn/Mask/GetMaskId");
        
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            request.AddHeader("Content-Type", "application/json");
            request.AddHeader("Cookie", "ARRAffinity=15f4ef39e421cfc89e66a46901447514712ba1a08aa54f79cd6f224ee1dbd05d");
            request.AddParameter("application/json", "{\n \"key\": \"W4rTnNboDAC8ADQSqGRoLIJJ\",\n \"maskUid\": \"DBDUPblsSR5uuP\"\n}", ParameterType.RequestBody);
            //var param = new MyClass { key = "W4rTnNboDAC8ADQSqGRo", maskUid = "DBDUPblsSR5uuP" };
            //request.AddJsonBody(param);
            IRestResponse response = client.Execute(request);
            
            Console.WriteLine(response.Content);
        }

        public class MyClass
        {
            public string key { set; get; }
            public string maskUid { set; get; }

        }
    }
}

https://blog.csdn.net/HermitSun/article/details/89889743?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2
https://stackoverflow.com/questions/5216567/is-this-statement-correct-http-get-method-always-has-no-message-body
https://stackoverflow.com/questions/978061/http-get-with-request-body
http://dkdevelopment.net/2010/05/18/dropbox-api-and-restsharp-for-a-c-developer/

https://blog.csdn.net/yang_5/article/details/42525247

https://restsharp.dev/

posted @ 2021-03-26 23:42  shoupifeng  阅读(163)  评论(0编辑  收藏  举报