我有同樣的問題其實問題是我使用x-www-form-urlencoded
哪些發送參數到URL(就像你這樣做,它似乎禁止imgur API團隊可能是一些安全問題),所以你需要使用表單數據。但是我沒有在api doc中找到它。下面我分享代碼示例的C#
using System.IO;
using System;
using System.Net;
using System.Text;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
class Program
{
static void Main()
{
sendRequest("https://api.imgur.com/oauth2/token");
}
private static void sendRequest(String url){
using(WebClient client = new WebClient())
{
System.Collections.Specialized.NameValueCollection reqparm = new System.Collections.Specialized.NameValueCollection();
reqparm.Add("client_id", "Your client_id");
reqparm.Add("client_secret", "Your client_secret");
reqparm.Add("grant_type", "authorization_code");
reqparm.Add("code", "your returned code");
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
System.Net.ServicePointManager.Expect100Continue = false;
byte[] responsebytes = client.UploadValues(url, "POST", reqparm);
string responsebody = Encoding.UTF8.GetString(responsebytes);
Console.WriteLine(responsebody);
}
}
}
是的,這是問題,我解決了它,但忘了更新問題。我希望這會幫助別人。謝謝! – kizisoft