使用Fiddler捕获401错误 - Twitter OAUTH 1.0

时间:2013-11-06 06:53:58

标签: asp.net http twitter-oauth fiddler http-status-code-401

我正在尝试查看发送/接收到Twitter的HTTP请求。我尝试下载fiddler4,但它没有注册401错误,我只收到500页错误。关于如何查看正在发送的请求的任何想法,以便我可以解决原因?

我尝试将该网站视为localhost,127.0.0.1和machinename。

Dim oAuthRequest As New Dictionary(Of String, String)
                oAuthRequest.Add("resource_url", "https://api.twitter.com/oauth/request_token")
                oAuthRequest.Add("oauth_callback", Server.UrlEncode("https://www.site.com/callback/"))
                oAuthRequest.Add("oauth_consumer_key", "xxxxxxxx")
                oAuthRequest.Add("oauth_nonce", Convert.ToBase64String(New ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString())))
                oAuthRequest.Add("oauth_signature_method", "HMAC-SHA1")
                oAuthRequest.Add("oauth_timestamp", CInt((DateTime.UtcNow - New DateTime(1970, 1, 1)).TotalSeconds).ToString)
                oAuthRequest.Add("oauth_token", "authorization_code")

Dim baseFormat As String = "oauth_callback=""{0}""&oauth_consumer_key=""{1}""&oauth_nonce=""{2}""&oauth_signature_method=""HMAC-SHA1""&oauth_timestamp=""{3}""&oauth_version=""" & Uri.EscapeDataString("1.0") & """"
Dim baseString As String = String.Format(baseFormat,
    oAuthRequest("oauth_callback"),
    oAuthRequest("oauth_consumer_key"),
    oAuthRequest("oauth_nonce"),
    oAuthRequest("oauth_timestamp"))

                baseString = String.Concat("POST&", Uri.EscapeDataString(oAuthRequest("resource_url")), "&", Uri.EscapeDataString(baseString))
                oAuthRequest.Add("oauth_signature", SHA1Base64Hash("xxxxxxx&", baseString))

Dim authHeaderFormat As String = "OAuth oauth_callback=""{0}"",oauth_consumer_key=""{1}"",oauth_nonce=""{2}"",oauth_signature=""{3}"",oauth_signature_method=""HMAC-SHA1"",oauth_timestamp=""{4}"",oauth_version=""1.0"""

Dim authHeader As String = String.Format(authHeaderFormat,
            Uri.EscapeDataString(oAuthRequest("oauth_callback")),
            Uri.EscapeDataString(oAuthRequest("oauth_consumer_key")),
            Uri.EscapeDataString(oAuthRequest("oauth_nonce")),
            Uri.EscapeDataString(oAuthRequest("oauth_signature")),
            Uri.EscapeDataString(oAuthRequest("oauth_timestamp")))


                ServicePointManager.Expect100Continue = False
Dim request As HttpWebRequest = CType(WebRequest.Create(oAuthRequest("resource_url")), HttpWebRequest)
                request.Headers.Add("Authorization", authHeader)
                request.Method = "POST"
                request.ContentType = "application/x-www-form-urlencoded"
                Try
Dim response As WebResponse = request.GetResponse()
                Catch ex As Exception
                    Text.text = ex.Message
                End Try

1 个答案:

答案 0 :(得分:0)

如果Fiddler向您显示HTTP / 500而不是HTTP / 401,那是因为服务器正在返回HTTP / 500。除非你告诉它这样做,否则Fiddler不会发明回复。