我想從窗戶訪問令牌直播通過使用此代碼遠程服務器返回錯誤:(401)未經授權
串requestUrl =「https://consent.live.com連接API /AccessToken.aspx「;
// Request the access token.
string postData = string.Format("{0}?wrap_client_id={1}&wrap_client_secret={2}&wrap_callback={3}&wrap_verification_code={4}&idtype={5}",
requestUrl,
"000000004C039809",
"l4VJekL1vFL1iFVmcP5qLkWv9ukY4mdl",
"http://ewshops.com",
"dac5d71d-d640-30d1-ebed-3576b132b3ec",
"cid");
byte[] postDataEncoded = System.Text.Encoding.UTF8.GetBytes(postData);
WebRequest req = HttpWebRequest.Create(requestUrl);
req.Method = "POST";
// req.
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = postDataEncoded.Length;
Stream requestStream = req.GetRequestStream();
requestStream.Write(postDataEncoded, 0, postDataEncoded.Length);
WebResponse res = req.GetResponse();
string responseBody = null;
using (StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8))
{
responseBody = sr.ReadToEnd();
}
// Process FORM POST.
NameValueCollection responseCollection = System.Web.HttpUtility.ParseQueryString(responseBody);
return responseCollection["wrap_access_token"];
,但我已經收到以下錯誤
遠程服務器返回錯誤:(401)未經授權。
我可以建議你在這個問題中清理一下代碼塊的格式(例如刪除所有這些不必要的空白行),以便它更易讀?請參閱[格式幫助](http://stackoverflow.com/editing-help) – stakx 2010-12-10 11:20:31
我已經重新格式化了這篇文章,謝謝 – Hadad 2010-12-10 12:01:57