无法获取HTTP Post请求的正确C#
本文关键字:请求 Post 获取 HTTP | 更新日期: 2023-09-27 18:20:30
我正在使用Oauth 1.0进行身份验证过程。我被困在获取请求令牌的第一步。执行以下请求会引发"远程服务器返回错误:(401)未经授权。"
Uri uri1 = new Uri("https://api.500px.com/v1/oauth/request_token");
string consumerKey = "ABFHGHIQYW4clmuXXXXXXXBy528gl2zEEEEN";
string consumerSecret = "BBGHGJnrJaKKjoScCFHJGJFKK6HVjjDHFJSDJDjno";
string timeStamp = myOAuth.GenerateTimeStamp();
string nonce = myOAuth.GenerateNonce();
myOAuth.includeVersion = true;
string signature = myOAuth.GenerateSignature(uri1, consumerKey, consumerSecret, "", "", "POST", timeStamp, nonce, OAuth.OAuthBase.SignatureTypes.HMACSHA1, out normalizedUrl, out normalizedRequestParameters);
request = (HttpWebRequest)WebRequest.Create("https://api.500px.com/v1/oauth/request_token");
request.Method = "POST";
request.KeepAlive = true;
request.UseDefaultCredentials = true;
request.Credentials = CredentialCache.DefaultCredentials;
request.Headers.Add("Authorization", "OAuth oauth_callback='"http://www.abcxyz.com'",oauth_consumer_key='"" +consumerKey + "'",oauth_nonce='"" +nonce + "'",oauth_signature_method='"HMAC-SHA1'",oauth_timestamp='"" + timeStamp + "'", oauth_version='"1.0'",oauth_signature=" + signature);
response = (HttpWebResponse)request.GetResponse();
所有参数都通过HTTP Post的"Authorization Header"传递。我的请求中肯定遗漏了一些东西,但无法弄清楚到底遗漏了什么。
任何建议或任何形式的帮助都将不胜感激。提前感谢。
add首先需要一个请求来获取令牌。之后创建另一个请求并将令牌作为参数传递。