Answer the question
In order to leave comments, you need to log in
Where could be the error in my c# POST request snippet?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
using System.Text;
using System.IO;
namespace POST
{
class Program
{
static void Main(string[] args)
{
using (var client = new HttpClient())
{
var url = "https://dns.api.gandi.net/api/v5/zones";
var data = new StringBuilder();
data.AppendLine(@"{""name"": ""megaso55.pw Zone""}");
using (var content = new StringContent(data.ToString(), Encoding.UTF8, "text/plain"))
{
using (var request = new HttpRequestMessage(HttpMethod.Put, url))
{
request.Headers.Add("X-Api-Key", "osuheropbwouibheruibwpj");
request.Content = content;
using (var response = client.SendAsync(request).Result)
{
var result = response.Content.ReadAsStringAsync().Result;
Console.WriteLine(result);
File.WriteAllText(@"C:\result.txt", result);
}
}
}
System.Threading.Thread.Sleep(1000000);
}
}
}
}
{"code": 405, "message": "The server could not comply with the request since it is either malformed or otherwise incorrect.", "object": "HTTPMethodNotAllowed", "cause": "Method Not Allowed"}
$ curl -D- -X POST -H "Content-Type: application/json" \
-H "X-Api-Key: $APIKEY" \
-d '{"name": "example.com Zone"}' \
https://dns.api.gandi.net/api/v5/zones
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question