【问题标题】:accessing https://api.twitter.com returns 403 error as forbidden访问 https://api.twitter.com 返回 403 错误为禁止
【发布时间】:2015-01-16 20:55:44
【问题描述】:

我正在尝试使用以下代码通过我的 .net 代码访问https://api.twitter.com

 var address = new Uri(TwitterBaseUri);
            var restTemplate = new RestTemplate(address);
            restTemplate.RequestInterceptors.Add(new BasicSigningRequestInterceptor(ConsumerKey, ConsumerSecret));
            restTemplate.MessageConverters.Add(new DataContractJsonHttpMessageConverter());

            string body = "grant_type=client_credentials";
            var entity = new HttpEntity(body);
            entity.Headers["Content-Type"] = "application/x-www-form-urlencoded;charset=UTF-8";
            var response = restTemplate.PostForObject<OAuthResponse>("oauth2/token", entity);
            _accessToken = response.AccessToken;

我在家里访问它时没有发现任何问题....但是当我连接到我的办公室 vpn 或在办公室访问它时)..它会引发 403 禁止错误。

我们获得了 twitter 的访问权限,并且我们可以访问 twitter.com,而不会在办公室遇到任何问题。谁能帮忙。

我们的测试应用程序正在发送以下连接请求:

CONNECT api.twitter.com:443 HTTP/1.1
Host: api.twitter.com
Proxy-Connection: Keep-Alive

回复如下:

HTTP/1.1 403 Forbidden
Cache-Control: no-cache
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Proxy-Connection: close
Connection: close
Content-Length: 513

【问题讨论】:

    标签: c# twitter-oauth


    【解决方案1】:

    从办公室访问 Twitter 时是否需要提供任何身份验证信息,例如网络用户名/密码?

    如果是,那么您需要在请求中传递相同的信息,以便能够通过 vpn 网络验证您的请求。

    上述建议的示例是

    ICredentials credentials = new     
    NetworkCredential("Joe",SecurelyStoredPassword,"mydomain");
            math.Credentials = credentials;
    

    【讨论】:

    • 不,我不需要提供任何类似的信息。
    猜你喜欢
    • 2015-05-14
    • 1970-01-01
    • 1970-01-01
    • 2017-12-15
    • 1970-01-01
    • 1970-01-01
    • 2011-12-27
    • 1970-01-01
    • 2017-01-04
    相关资源
    最近更新 更多