我花了好几天的时间来研究这件事,现在已经没有进一步的进展了。我试图允许用户使用Twitter登录到我的.Net (MVC)网站。它曾经工作过,但在某个时候它停止了在我的生产‘ve服务器上的工作(自从我注意到它停止工作后,我已经删除了补丁,但是它仍然不能工作)。
问题是对https://api.twitter.com/oauth/request_token的初始API调用。在我的本地主机Windows10dev机器上,它工作正常,并返回: oauth_token=xxx&oauth_token_secret=xxx&oauth_callback_confirmed=true
但在网络服务器上,它返回了一页贵宾狗坐在椅子上的错误404!
我在使用的任何库(TweetSharp、TweetInv、Microsoft.Owin.Security.Twitter甚至手动HttpWebRequest!)中都会遇到同样的问题。所以这与此无关。
它在我的本地主机(Visual 2022)上工作。它在本地机器和我的web服务器上使用邮递员工作。
它不工作在我的web服务器(服务器2012 R2)通过我的网站。
由于库不起作用,我使用HttpWebRequest创建了一个可用的本地主机示例,这样我就可以使用headers等来反映Postman/Fiddler。
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.twitter.com/oauth/request_token");
request.Method = "POST";
request.Headers["Authorization"] = OAuthHeader;
request.Accept = "*/*";
request.ContentType = "application/x-www-form-urlencoded";
request.KeepAlive = true;
request.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);同样,它在本地工作,但在我的web服务器上不起作用。
我的MVC站点使用.net 4.8 (targetFramework="4.8")。
我在应用程序设置中将URL(本地主机IP和我的活动域回调URL)添加到我的回调设置中。
我使用Oauth1.0a和只读权限。
我已经使用IISCrypto来验证TLS1.2是启用的,而且看起来还可以。
我的想法快用完了!!有人有指点吗?谢谢!
更新
我运行了一个简单的CURL命令,如下所示:

发布于 2022-06-06 05:57:19
尝试使用curl命令从服务器机器中检查,如下所示

当您调用api.twitter.com时,需要确保您使用的是TLS1.2 - Twitter不再支持旧的TLS v1,如果遇到TLS问题,请尝试通过执行以下命令更新服务器机器上的Powershell以始终使用TLS1.2:
Net.ServicePointManager::SecurityProtocol = Net.SecurityProtocolType::Tls12我得到了预期的响应,而不是404错误。
PS C:\Users\onsolveadmin> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
PS C:\Users\onsolveadmin> curl https://api.twitter.com/oauth/request_token -v
VERBOSE: GET https://api.twitter.com/oauth/request_token with 0-byte payload
curl : {"errors":[{"code":215,"message":"Bad Authentication data."}]}
At line:1 char:1
+ curl https://api.twitter.com/oauth/request_token -v
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand那个错误消失了,然后确保
从您的代码库中,您可以确保它使用TLS1.2
对于我来说,这些行引起了问题,所以我删除了它们,我在2019年为修复TLS问题本身添加了这些代码。

发布于 2022-06-07 16:13:21
经过几天的调试,我终于让它开始工作了。这与Schannel/TLS/密码套件有关,但我不太清楚具体的修复是什么:https://www.alkanesolutions.co.uk/2022/06/07/twitter-api-giving-http-404-not-found-when-requesting-a-token/
https://stackoverflow.com/questions/72375797
复制相似问题