1
我正在嘗試使用提供的API從Wordnik檢索身份驗證令牌。但是,我似乎無法讓它工作。我似乎被卡住了401和403錯誤。Wordnik身份驗證錯誤
以下是代碼我使用請求從API認證:
string authRequest =
String.Format("http://api.wordnik.com//v4/account.json/authenticate/{0}",
this.userName);
HttpWebRequest request = WebRequest.Create(authRequest) as HttpWebRequest;
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/x-www-form-urlencoded";
// When this is added, I get 403 errors
///request.Headers.Add("api_key", APIKey);
string postData = "password=" + password;
byte[] encodedData = UTF8Encoding.UTF8.GetBytes(postData);
request.ContentLength = encodedData.Length;
Stream stream = request.GetRequestStream();
stream.Write(encodedData, 0, encodedData.Length);
stream.Close();
string responseText;
using(HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
using(StreamReader reader = new StreamReader(response.GetResponseStream()))
{
responseText = reader.ReadToEnd();
Console.WriteLine(responseText);
Console.ReadLine();
}
}
任何你能告訴我我在做什麼錯誤?
任何輸入表示讚賞。
似乎沒有什麼錯 - 你試過問上https://groups.google.com/forum/?fromgroups#!forum/wordnik-API?這是他們的谷歌集團。 – JTeagle 2012-03-15 13:31:45
我已向他們的論壇添加了一篇文章。感謝您的幫助。 – achillesminor 2012-03-15 14:21:54