主题
这是在Postman中导入的CURL请求
curl --location 'https://api.telegra.ph/createPage' \
--header 'Content-Type: application/json' \
--data '{"access_token":"26fb54ae0ace42a66d743ec00519a604236dca21e80b588d012833b6955d", "title": "Mytitle", "content": [{"tag": "p", "children": ["Hello, world!"]}]}'
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$body = @"
{`"access_token`":`"26fb54ae0ace42a66d743ec00519a604236dca21e80b588d012833b6955d`", `"title`": `"Mytitle`", `"content`": [{`"tag`": `"p`", `"children`": [`"Hello, world!`"]}]}
"@
$response = Invoke-RestMethod 'https://api.telegra.ph/createPage' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
这是生成 POSTMAN 的C# 代码https://dotnetfiddle.net/eRJHRN ,
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.telegra.ph/createPage");
var content = new StringContent("{\"access_token\":\"26fb54ae0ace42a66d743ec00519a604236dca21e80b588d012833b6955d\", \"title\": \"Mytitle\", \"content\": [{\"tag\": \"p\", \"children\": [\"Hello, world!\"]}]}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
答案来了:
{"ok":false,"error":"ACCESS_TOKEN_INVALID"}
据说不是有效的令牌。
为什么会这样呢?