Twitter api响应难以理解

时间:2012-12-06 09:24:36

标签: encoding asp-classic twitter

我们一直在使用twitter api一段时间但突然间它停止了工作。追溯它似乎ASP vbscript无法读取MSXML2.ServerXMLHTTP请求的响应。

即使对页面的简单GET请求也会变成无效的字符。在浏览器中打开https://api.twitter.com/oauth/request_token将显示字符串“无法验证oauth签名和令牌”。当我尝试在ASP中获得相同的东西时,它返回不可读的数据。

<% @LANGUAGE="VBSCRIPT" %>
<%
Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXMLHTTP.open "GET", "https://api.twitter.com/oauth/request_token", false
objXMLHTTP.send ""

Response.Write "<pre>"
Response.Write objXMLHTTP.responseText
Response.Write "<hr>"
Response.Write objXMLHTTP.getAllResponseHeaders()
Response.Write "</pre>"
%>

输出是:

?
------
Date: Thu, 06 Dec 2012 09:12:17 GMT
Status: 401 Unauthorized
X-MID: caa889032d29f5316a855dcadd748211ed4ee276
X-Frame-Options: SAMEORIGIN
Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
Content-Type: text/html; charset=utf-8
Last-Modified: Thu, 06 Dec 2012 09:12:16 GMT
Pragma: no-cache
X-Transaction: dd71c8da0813a966
Expires: Tue, 31 Mar 1981 05:00:00 GMT
X-Runtime: 0.02056
Set-Cookie: k=10.36.75.125.1354785136971277; path=/; expires=Thu, 13-Dec-12 09:12:16 GMT; domain=.twitter.com
Set-Cookie: guest_id=v1%3A135478513698331395; domain=.twitter.com; path=/; expires=Sat, 06-Dec-2014 21:12:16 GMT
Set-Cookie: _twitter_sess=BAh7CDoPY3JlYXRlZF9hdGwrCFihfG87ASIKZmxhc2hJQzonQWN0aW9uQ29u%250AdHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7ADoHaWQiJTMx%250AMzI0YjhkNDc4YmQ4MDExMjlhNTI2NWU5OTAxNDVi--97206a42b05d8cb85fbd88ccd9ccb8aaca39ebef; domain=.twitter.com; path=/; HttpOnly
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 62
Server: tfe

?实际上是一个包含更多字符的字符串,但由于它包含CHR(0)而无法处理。

现在我认为可能是因为Content-Encoding: gzip,但即使发送objXMLHTTP.setRequestHeader "Accept-Encoding", "none"(或任何其他格式),它也会返回相同的内容。

任何人都知道我能做些什么来解决这个问题?

1 个答案:

答案 0 :(得分:2)

我现在已经看了好几个小时,刚问完我就找到了这个! Twitter API要求用户代理与请求一起发送很长时间。所以它很简单:

Set objXMLHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP.6.0")
objXMLHTTP.open "GET", "https://api.twitter.com/oauth/request_token", false
objXMLHTTP.SetRequestHeader "User-Agent", "something"
objXMLHTTP.send()