基类用的OauthBase.csprivate
string
DoRequest1212()
{
string
id =
"UB7XDF"
;
//Request.Form["Id"].ToString();
string
code =
"U2D2N1G621"
;
// Request.Form["Code"].ToString();
string
ip = Request.ServerVariables[
"REMOTE_ADDR"
].ToString();
//"10.0.235.76"; //
var verifyUrl =
"https://tcnc.eu/51RH/api/v2/verify/"
+ id +
"-"
+ code;
var paras =
"?user_ip="
+ ip +
"&user_agent=Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11"
;
string
finalurl = verifyUrl + paras;
var authBase =
new
OAuth.OAuthBase();
var oauth_consumer_key =
"VCOvW2eSbiq3kw6og4Jw"
;
var oauth_consumer_secret =
"4Ln4/Flpe98oDVMhVwTVsyx5b2A+6KL"
;
string
normalizedUrl =
""
;
string
normalizedRequestParameters =
""
;
var oauth_nonce = authBase.GenerateNonce();
var oauth_timestamp = authBase.GenerateTimeStamp();
string
sig = authBase.GenerateSignature(
new
Uri(finalurl), oauth_consumer_key, oauth_consumer_secret,
null
,
null
,
"GET"
, oauth_timestamp,
oauth_nonce,
out
normalizedUrl,
out
normalizedRequestParameters);
var webRequest = WebRequest.Create(finalurl)
as
HttpWebRequest;
var authorizationParas =
new
StringBuilder();
authorizationParas.Append(
"Authorization: OAuth "
);
authorizationParas.Append(
"realm=\"tcnc.eu\""
);
authorizationParas.AppendFormat(
",oauth_consumer_key={0},"
, oauth_consumer_key);
authorizationParas.AppendFormat(
"oauth_nonce={0},"
, oauth_nonce);
authorizationParas.AppendFormat(
"oauth_timestamp={0},"
, oauth_timestamp);
authorizationParas.AppendFormat(
"oauth_signature_method={0},"
,
"HMAC-SHA1"
);
authorizationParas.AppendFormat(
"oauth_version={0},"
,
"1.0"
);
authorizationParas.AppendFormat(
"oauth_signature={0}"
, authBase.UrlEncode(sig));
webRequest.Headers.Add(authorizationParas.ToString());
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
return
response.GetResponseStream().ToString();
}
HTTP 错误 401.1 - 未经授权:访问由于凭据无效被拒绝。
authorizationParas 你这个对象只存的应该都是与权限验证相关的信息,
加了之后还是没有权限, 检查生成的这一串字符串是否是正确的格式,
或者是否遗漏了与验证相关的信息,