[英]gandi api call from C# returns 400. Its Working Fine from Postman
I have create gandi api code for create domain and for that i have write below code, but it show me 400 bad request error我已经为创建域创建了 gandi api 代码,为此我写了下面的代码,但它显示了 400 错误请求错误
public async System.Threading.Tasks.Task<JsonResult> InsertDomain(DomainDetails domainDetails)
{
HttpResponseMessage response = new HttpResponseMessage();
try
{
var url = "https://api.gandi.net/v5/domain/domains";
using ( var client = new HttpClient() )
{
var json = new JavaScriptSerializer().Serialize(domainDetails);
HttpContent HttpContent = new StringContent(json, Encoding.UTF8, "application/json");
var MyHttpClient = new HttpClient();
MyHttpClient.DefaultRequestHeaders.Add("authorization", GANDI_API_Key);
response = await MyHttpClient.PostAsync(url, HttpContent);
}
}
catch ( Exception ex )
{
throw;
}
return Json(new { result = response }, JsonRequestBehavior.AllowGet);
}
but when i try to pass same data using postman then it's working fine below code is my postman data但是当我尝试使用 postman 传递相同的数据时,它工作正常,下面的代码是我的 postman 数据
Body
{
"fqdn":"dedasdom1906.com",
"owner":
{
"city":"Paris",
"given":"Alice",
"family":"Doe",
"zip":"75001",
"country":"FR",
"streetaddr":"5 rue neuve",
"phone":"+33.123456789",
"state":"FR-J",
"type":"0",
"email":"alice@example.org"
}
}
Header
authorization : Apikey
Content-Type : application/json
if none of this help you, please give more details.如果这些都对您没有帮助,请提供更多详细信息。
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
if none of this help you, please give more details.如果这些都对您没有帮助,请提供更多详细信息。
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
For the https://api.gandi.net/v5/domain/domains
endpoint, use HTTP GET
( HttpClient.GetAsync
) to retrieve a list of your domains.对于https://api.gandi.net/v5/domain/domains
端点,使用 HTTP GET
( HttpClient.GetAsync
) 检索您的域列表。 Use HTTP POST
( HttpClient.PostAsync
) to create a new domain.使用 HTTP POST
( HttpClient.PostAsync
) 创建一个新域。
If you're trying to POST
JSON, I would use the PostAsJsonAsync
method, example here :如果您尝试发布POST
,我将使用PostAsJsonAsync
方法, 例如:
static async Task<Uri> CreateProductAsync(Product product)
{
HttpResponseMessage response = await client.PostAsJsonAsync(
"api/products", product);
...
Also note your auth header needs to start with "apikey" though it looks like you have that working.另请注意,您的身份验证 header 需要以“apikey”开头,尽管看起来您可以正常工作。 Curl example: Curl 示例:
curl -X GET \
https://api.gandi.net/v5/domain/domains \
-H 'authorization: Apikey your-api-key'
https://api.gandi.net/docs/domains/ https://api.gandi.net/docs/domains/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.