.NET C# 用の foursquare SDK があることを知っているかもしれません。私は開発者のリファレンスに基づいてやっていますが、トークンのリクエスト中に失敗しました.エラーが発生し続けます. 私はVS 2008を使用しており、開発中のサーバーです。URLの書き換えのためにこのエラーの前に検索しましたが、IISでホストされておらず、web.configもチェックしていますが、運もありません。助けてください、ありがとう。
これは私のエラーです:
パス '/login' へのアクセスに使用される HTTP 動詞 POST は許可されていません。
これは私の実装です:
HttpWebRequest request = null;
HttpWebResponse response = null;
StreamReader responseStream = null;
ASCIIEncoding ascii = null;
string key = ConfigurationManager.AppSettings["key"];
string secret = ConfigurationManager.AppSettings["secret"];
string callback = ConfigurationManager.AppSettings["callback"];
string obtainTokenUrl = ConfigurationManager.AppSettings["obtainTokenUrl"];
try
{
string postData = "client_id=" + key + "&response_type=code&redirect_uri=" + callback;
ascii = new ASCIIEncoding();
byte[] postBytes = ascii.GetBytes(postData);
try
{
request = WebRequest.Create(obtainTokenUrl) as HttpWebRequest;
}
catch (UriFormatException)
{
request = null;
}
if (request == null)
{
throw new ApplicationException("Invalid URL: " + obtainTokenUrl);
}
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postBytes.Length;
//add post data to request
Stream postStream = request.GetRequestStream();
postStream.Write(postBytes, 0, postBytes.Length);
postStream.Close();
response = (HttpWebResponse)request.GetResponse();
Encoding encode = Encoding.GetEncoding("utf-8");
responseStream = new StreamReader(response.GetResponseStream(), encode);
Response.Write(responseStream.ReadToEnd());