0

我正在尝试使用 API 从 LinkedIn 获取评论,但出现以下错误

The remote server returned an error: (401) Unauthorized.

[WebException: The remote server returned an error: (401) Unauthorized.]
System.Net.HttpWebRequest.GetResponse() +6442408
Demo.WebForm1.Page_Load(Object sender, EventArgs e) in y:\Demo\Demo\WebForm1.aspx.cs:38
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean   includeStagesAfterAsyncPoint) +772

我已经写了这段代码,在 Page_Load 我已经给出了请求

protected void Page_Load(object sender, EventArgs e) {
    string strURL = "http://api.linkedin.com/v1/groups/67657/posts?order=recency&category=discussion";
    System.Net.HttpWebRequest objWebRequest = null;
    System.Net.HttpWebResponse objWebResponse = null;
    System.IO.StreamReader streamReader = null;
    string strHTML = null;

    System.Net.ServicePointManager.ServerCertificateValidationCallback = 
        delegate(object s, 
                System.Security.Cryptography.X509Certificates.X509Certificate certificate, 
                System.Security.Cryptography.X509Certificates.X509Chain chain, 
                System.Net.Security.SslPolicyErrors sslPolicyErrors) 
                { return true; };

    objWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(strURL);
    objWebRequest.Method = "GET";

    objWebRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;

    //Here I'm getting an error
    objWebResponse = (System.Net.HttpWebResponse)objWebRequest.GetResponse();

    streamReader = new System.IO.StreamReader(objWebResponse.GetResponseStream());

    strHTML = streamReader.ReadToEnd();


    streamReader.Close();
    objWebResponse.Close();
    objWebRequest.Abort();

    Response.ContentType = "text/xml";
    Response.Write(strHTML);
    Response.End();
}
4

0 回答 0