Skip to content

Instantly share code, notes, and snippets.

@donma
Created October 28, 2020 01:48
HttpClient clientGetZones = new HttpClient();
clientGetZones.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//clientGetZones.DefaultRequestHeaders.Add("Authorization", " Bearer [API TOKEN]");
clientGetZones.DefaultRequestHeaders.Add("Authorization", " Bearer abcdedghijklmnopQRSTUV_ABCD_ggggPqCD");
//var url1 = "https://api.cloudflare.com/client/v4/zones/[ZONE_ID]/dns_records";
var url1 = "https://api.cloudflare.com/client/v4/zones/2836714271b942af9386532b00b5579c/dns_records";
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, url1);
var req = new AddDNSRequest();
req.name = "demo1";
req.proxied = true;
req.type = "A";
req.content = "163.13.202.22";
requestMessage.Content = new StringContent(JsonConvert.SerializeObject(req), Encoding.UTF8, "application/json");
HttpResponseMessage response = clientGetZones.SendAsync(requestMessage).GetAwaiter().GetResult();
var res = response.Content.ReadAsStringAsync().Result.ToString();
ltlResult.Text = JsonConvert.SerializeObject(res);
//result
//{"id":"52991924ec82a967d45caab25cbf6a90","zone_id":"2836714271b942af9386532b00b5579c","zone_name":"sample.com","name":"demo1.sample.com","type":"A","content":"163.13.202.22","proxiable":true,"proxied":true,"ttl":1,"locked":false,"meta":{"auto_added":false,"managed_by_apps":false,"managed_by_argo_tunnel":false,"source":"primary"},"created_on":"2020-10-28T01:46:39.057696Z","modified_on":"2020-10-28T01:46:39.057696Z"},"success":true,"errors":[],"messages":[]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment