繁体   English   中英

带有 json 正文的 RestSharp HyperCo 错误请求

[英]RestSharp HyperCo bad request with json body

`

var client = new RestClient("https://api.hyper.co/v6/licenses/");
                    var request = new RestRequest(licensekey);
                    request.AddHeader("accept", "application/json");
                    request.AddHeader("Authorization", "Bearer secret key");
                    RestResponse response = await client.GetAsync(request);

                    if (response.IsSuccessStatusCode == true)
                    {
                        LicenseResponse.Text = "Sucess";
                        Refresh();
                        Thread.Sleep(1000);
                        LicenseResponse.Location = new Point(450, 330);
                        var body = "{\"hwid\":\"" + harware_id + "\"}";
                        var requestMetadata = new RestRequest($"{licensekey}/metadata");
                        requestMetadata.AddHeader("accept", "application/json");
                        requestMetadata.AddHeader("content-type", "application/json");
                        requestMetadata.AddHeader("Authorization", "Bearer secret key");
                        requestMetadata.RequestFormat=DataFormat.Json;
                        requestMetadata.AddJsonBody(body) ;
                        RestResponse responseMetadata = await client.GetAsync(requestMetadata);
                        if (responseMetadata.IsSuccessStatusCode == true)
                        {
                            LicenseResponse.Text = responseMetadata.ToString();
                            Refresh();
                        } else if (responseMetadata.StatusCode == System.Net.HttpStatusCode.NotFound) {
                            LicenseResponse.Text = responseMetadata.ToString();
                            Refresh();
                        } else if (responseMetadata.StatusCode == System.Net.HttpStatusCode.Unauthorized) {
                            LicenseResponse.Text = responseMetadata.ToString();
                            Refresh();
                        }
                        toolForm toolForm = new toolForm();
                        toolForm.Visible = true;
                        this.Visible= false;
                    }
                    else
                    {
                        LicenseResponse.Text = "Error";
                        Refresh();
                        LicenseResponse.Location = new Point(438, 330);
                        Thread.Sleep(3000);
                        Environment.Exit(0);
                    }

`

这是我的代码,当我开始他得到一个错误的请求响应时,有人对我有帮助提示吗? (你可以问我代码的其他部分或其他

我想更新特定许可证的 hyper.co 的元数据部分。 如果它在 hyper.co 的仪表板中工作,元数据部分将会改变。

正如我在评论中所写,在我看来,您使用了错误的 werb to 方法(GET 而不是 PATCH),此外您的数据 model 也有误 这是许可证元数据端点的示例:

var client = new RestClient("https://api.hyper.co/v6/licenses/license/metadata");
var request = new RestRequest(Method.PATCH);
request.AddHeader("accept", "application/json");
request.AddHeader("content-type", "application/json");
IRestResponse response = client.Execute(request);

在文档中,您可以为指定语言生成示例(在右侧) https://docs.hyper.co/reference/update-license-metadata

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM