C# 无效的请求参数

C# 无效的请求参数,c#,json,http,post,restsharp,C#,Json,Http,Post,Restsharp,下午好,我一直在用C#做一个小的开发,用于HTTP POST中的请求 我有以下问题,在尝试c#时,以下问题对我不起作用 using RestSharp; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Thre

下午好,我一直在用C#做一个小的开发,用于HTTP POST中的请求

我有以下问题,在尝试c#时,以下问题对我不起作用

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

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

        [Obsolete]
        private void button1_Click(object sender, EventArgs e)
        {
            //URL:
            var client = new RestClient("Hidden URL");
            var request = new RestRequest("/", Method.POST);

            //Headers:
            request.AddHeader("X-Authorization", "Hidden Token");
            request.AddHeader("Content-Type", "application/json");

            //Body json:
            request.AddParameter(
            "application/json",
            "{ \"taskRelativePath\": \"My Tasks\\VPN.atmx\", \"botRunners\": [{ \"client\": \"DESKTOP -Hidden name\", \"user\": \"botrunner03\"}], \"runWithRDP\": \"true\" }", // <- your JSON string
             ParameterType.RequestBody);

            IRestResponse response = client.Execute(request);

            var content = response.Content;

            txtResponse.Text = content;

        }

    }
}
使用RestSharp;
使用制度;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
Net系统;
使用System.IO;
使用Newtonsoft.Json.Linq;
名称空间应用程序\u Llamadas\u API
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
}
[过时]
私有无效按钮1\u单击(对象发送者,事件参数e)
{
//网址:
var client=新的RestClient(“隐藏URL”);
var请求=新的重新请求(“/”,Method.POST);
//标题:
AddHeader(“X-授权”、“隐藏令牌”);
AddHeader(“内容类型”、“应用程序/json”);
//正文json:
request.AddParameter(
“应用程序/json”,

“{\'taskRelativePath\”:“我的任务\\VPN.atmx\”,“'botRunners\”:[{\'client\”:“DESKTOP-Hidden name\”,“user\”:“botrunner03\”}],“runWithRDP\”:“true\”,//请求无效,因为JSON转义不正确。您需要转义
我的任务\\VPN
中的每个反斜杠

“{\'taskRelativePath\\”:“我的任务\\\\VPN.atmx\”,“botRunners\”:[{\'client\':\'DESKTOP-Hidden name\”,“user\':\'botrunner03\”,“runWithRDP\”:“true\”);
否则,它将按如下方式读取JSON(注意只有一个反斜杠):

{

“taskRelativePath:“我的任务\VPN.atmx”,JSON不允许反斜杠。请尝试:“{”taskRelativePath:“我的任务\\VPN.atmx”,“botRunners:[{”客户端“:“桌面-隐藏名称”,“用户“:“botrunner03”}],“runWithRDP:“true”}\\“runWithRDP\”:“true\”我的第一个猜测是,此参数需要一个布尔值,而您正在传入一个字符串值。请将其更改为“runWithRDP”:true和rerunI已尝试但未成功,我曾尝试使用另一个api,其工作方式如下:选项1工作,选项2不工作我已尝试使用TravisActon,看起来相同的错误再次出现。我在postman上尝试了此操作,并且工作正常