Restsharp 在正文中添加了引导,如何删除它?

发布于 2025-01-11 19:32:25 字数 2324 浏览 2 评论 0原文

我的代码如下,非常简单。我试图匹配邮递员呼叫,它非常接近,但是当我在邮递员中进行呼叫时,它看起来有所不同,特别是restsharp在我在fiddler中看到的身体周围添加了一个引导。该指南似乎中断了我的通话,如何删除它?

 string url = "https://url/api/";

                var client = new RestClient(url);

                client.AddDefaultHeader("x-ads-dev", "Key");
                var request = new RestRequest("telemetry", Method.Post);
               request.AddHeader("Content-Type", "application/json");
                request.AddParameter("application/json", datapoint, ParameterType.RequestBody);
                var response =  await client.PostAsync(request);

这是 Fiddler 显示的内容:

POST http://url/api/telemetry HTTP/1.1
Host: api.adsprism.com
x-ads-dev: key
Accept: application/json, text/json, text/x-json, text/javascript, application/xml, text/xml
User-Agent: RestSharp/107.3.0.0
Accept-Encoding: gzip, deflate, br
Content-Type: application/json; boundary="717cb9fd-684d-424e-bd0a-cf6b0bb11bac"
Content-Length: 398

--717cb9fd-684d-424e-bd0a-cf6b0bb11bac
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name="application/json"

[{"entityID":2123,"locationID":33,"data":[{"dateTime":"2020-08-03 23:05:00","reading":0,"flags":0,"quality":15,"ignore":false},{"dateTime":"2020-09-27 03:10:00","reading":0,"flags":0,"quality":15,"ignore":false}]}]
--717cb9fd-684d-424e-bd0a-cf6b0bb11bac--

fiddler 邮递员请求中不存在 --717cb9fd-684d-424e-bd0a-cf6b0bb11bac--guid,并且它似乎导致来自 Restsharp 的错误请求错误。那么如何让restsharp不生成呢?

编辑:添加邮递员提琴手以显示差异。

POST http://api.url/api/telemetry HTTP/1.1
x-ads-dev: key
Content-Type: application/json
User-Agent: PostmanRuntime/7.29.0
Accept: */*
Postman-Token: 5f186e6d-cad0-482c-b7b8-a50559f24b87
Host: api.adsprism.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 513

[
    {
        "entityID": 2123,
        "locationID": 33,
        "data": [
            {
                "dateTime": "2020-08-03 23:05:00",
                "reading": 0,
                "flags": 0,
                "quality": 0,
                "ignore": true
            },
            {
                "dateTime": "2020-09-27 03:10:00",
                "reading": 0,
                "flags": 0,
                "quality": 0,
                "ignore": true
            }
        ]
    }
]

My code is below, it is very simple. I was trying to match a postman call and it came pretty close, but when I made the call in postman it looks different, specifically restsharp adds a guid around the body that I saw in fiddler. The guide seems to break my calls, how do I remove it?

 string url = "https://url/api/";

                var client = new RestClient(url);

                client.AddDefaultHeader("x-ads-dev", "Key");
                var request = new RestRequest("telemetry", Method.Post);
               request.AddHeader("Content-Type", "application/json");
                request.AddParameter("application/json", datapoint, ParameterType.RequestBody);
                var response =  await client.PostAsync(request);

And here is what Fiddler shows:

POST http://url/api/telemetry HTTP/1.1
Host: api.adsprism.com
x-ads-dev: key
Accept: application/json, text/json, text/x-json, text/javascript, application/xml, text/xml
User-Agent: RestSharp/107.3.0.0
Accept-Encoding: gzip, deflate, br
Content-Type: application/json; boundary="717cb9fd-684d-424e-bd0a-cf6b0bb11bac"
Content-Length: 398

--717cb9fd-684d-424e-bd0a-cf6b0bb11bac
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name="application/json"

[{"entityID":2123,"locationID":33,"data":[{"dateTime":"2020-08-03 23:05:00","reading":0,"flags":0,"quality":15,"ignore":false},{"dateTime":"2020-09-27 03:10:00","reading":0,"flags":0,"quality":15,"ignore":false}]}]
--717cb9fd-684d-424e-bd0a-cf6b0bb11bac--

The --717cb9fd-684d-424e-bd0a-cf6b0bb11bac-- guid is not there in the fiddler postman request and it seems to be causing a bad request error from restsharp. So how do I make restsharp not generate it?

EDIT: Added postman fiddler to show the difference.

POST http://api.url/api/telemetry HTTP/1.1
x-ads-dev: key
Content-Type: application/json
User-Agent: PostmanRuntime/7.29.0
Accept: */*
Postman-Token: 5f186e6d-cad0-482c-b7b8-a50559f24b87
Host: api.adsprism.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 513

[
    {
        "entityID": 2123,
        "locationID": 33,
        "data": [
            {
                "dateTime": "2020-08-03 23:05:00",
                "reading": 0,
                "flags": 0,
                "quality": 0,
                "ignore": true
            },
            {
                "dateTime": "2020-09-27 03:10:00",
                "reading": 0,
                "flags": 0,
                "quality": 0,
                "ignore": true
            }
        ]
    }
]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乱世争霸 2025-01-18 19:32:25

阅读文档会有所帮助。

const string url = "https://url/api/";

var client = new RestClient(url);
client.AddDefaultHeader("x-ads-dev", "Key");

var request = new RestRequest("telemetry", Method.Post);
request.AddStringBody(datapoint, DataType.Json);
var response =  await client.PostAsync(request);

Reading the docs can help.

const string url = "https://url/api/";

var client = new RestClient(url);
client.AddDefaultHeader("x-ads-dev", "Key");

var request = new RestRequest("telemetry", Method.Post);
request.AddStringBody(datapoint, DataType.Json);
var response =  await client.PostAsync(request);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文