我正在处理简单的Web应用程序,我需要在我的应用程序中从outlook API获取访问令牌以使用员工姓名及其图像。我已编写代码并且能够通过Outlook登录但我的访问令牌将为null 。请在下面找到我的代码:
public void GetResponseCallback(IAsyncResult asynchronousResult)
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
// End the operation
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
string responseString = streamRead.ReadToEnd();
access_token = responseString;
// Close the stream object
streamResponse.Close();
streamRead.Close();
// Release the HttpWebResponse
response.Close();
allDone.Set();
}
答案 0 :(得分:1)
HttpWebRequest request =(HttpWebRequest)WebRequest.Create(“some url”);
request.Method =“POST”;
request.ContentType =“application / x-www-form-urlencoded”;
request.UserAgent =“Mozilla / 5.0(兼容; MSIE 9.0; Windows NT 7.1; Trident / 5.0)”;
request.Accept =“/”;
request.UseDefaultCredentials = true;
request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
doc.Save(request.GetRequestStream());
HttpWebResponse resp = request.GetResponse()as HttpWebResponse;
希望有所帮助