简体   繁体   中英

POST with API in C#

I'm trying to POST data via an API but i'm getting an error 420 'Enhance your calm'.

If there is something i'm doing wrong ? (if you have another method in C# to POST in an API always welcome to share your solution )

Thank you

        try {
            HttpClient client2 = new HttpClient();
            client2.BaseAddress = new Uri("https://kbhb-officialpayments-test.sportlink-interfaces.net/entity/kbhb/officialpayments/UnionOfficialOfficialAssignment");
            client2.DefaultRequestHeaders.Add("Authorization", "Bearer aaafdsqgfdsgfdsgfzq");
            client2.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));//ACCEPT header

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "");
            request.Content = new StringContent("{\"PersonId\":\""+ personID + "\",\"FunctionId\":\"" + functionID + "\",\"ExternalMatchId\":\"" + matchID + "\",\"DistrictId\":\"" + district + "\"}", Encoding.UTF8, "application/json");//CONTENT-TYPE header

            client2.SendAsync(request)
                  .ContinueWith(responseTask => {
                      Console.WriteLine("Response: {0}", responseTask.Result);
                  });
        } catch (Exception ex) {
            Console.WriteLine(ex.Message);
        }

If there is something i'm doing wrong ?

420 is the code you get from the server. It's not official, so you'd have to ask the server provider what it means and what you should do.

Normally, 420 is another way to say you are rate limited (so actually status code 429). You sent too many requests over a short timeframe, so the service is blocking you. Again, whether that is the case, what constitutes "too many" or "timeframe" in their implementation is specific to their implementation and is something we cannot say. Contact them and ask.

It seems you are being limited.

The status code 420 : Not part of the HTTP standard, but introduced by Twitter. This was used by Version 1 of their API when requests from a particular client were being rate limited.

The 420 Enhance Your Calm status code means that you are being rate limited. It's similar to 429: Too many Requests . This means you are sending what they consider to be too many requests, too quickly.

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