简体   繁体   中英

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);
                    }

`

This is my code, when I start him got a bad request response, someone have a help tips for me? (you can ask me other part of the code or other th

I want to update the metadata part of hyper.co of a specific license. If it work in the dashboard of hyper.co the metadata part will change.

As I wrote in the comments, it seems to me that you are using the wrong werb to method (GET instead of PATCH), in addition you have the wrong data model This is example for license metadata endpoint:

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);

in documentation you can generate examples for specified language (on the right) https://docs.hyper.co/reference/update-license-metadata

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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