[英]Accessing Mt Gox API via http-conduit-0.1.9.3: query string causes timeout
I'm trying to access the Mt Gox REST API using http-conduit . 我正在尝试使用http-conduit访问Mt Gox REST API。 Queries that just have a path (eg https://data.mtgox.com/api/2/BTCUSD/money/ticker ) work fine, but when I add a queryString to the request it times out.
仅具有路径的查询(例如https://data.mtgox.com/api/2/BTCUSD/money/ticker )可以正常工作,但是当我向请求中添加queryString时,它会超时。
So this works: 所以这有效:
mtGoxRequest :: String -> QueryText -> Request m
mtGoxRequest p qt = def {
secure = True,
host = "data.mtgox.com",
port = 443,
method = "GET",
path = fromString $ "api/2/" ++ p,
queryString = renderQuery False $ queryTextToQuery qt,
responseTimeout = Just 10000000
}
currencyTicker :: Request m
currencyTicker = mtGoxRequest "BTCUSD/money/ticker" []
But this times out: 但这超时了:
tradeStream :: Currency -> UTCTime -> Request m
tradeStream t = mtGoxRequest
"BTCUSD/money/trades/fetch"
[("since", Just $ T.pack $ utcToGoxTime t)]
The difference seems to be in the use of a queryString: when I added the bogus query "foo=bar" to the currencyTicker that timed out too. 区别似乎在于对queryString的使用:当我将假查询“ foo = bar”添加到也超时的currencyTicker时。
However all this works fine in the web browser: going to https://data.mtgox.com/api/2/BTCUSD/money/ticker?foo=bar instantly returns the correct error message instead of timing out. 但是,所有这些操作在Web浏览器中都可以正常工作:转到https://data.mtgox.com/api/2/BTCUSD/money/ticker?foo=bar立即返回正确的错误消息,而不是超时。 The trade fetch URL works as well, although I won't include a link because the "since" argument says how far back to go.
交易提取网址也能正常工作,尽管我不会包含链接,因为“自”参数说明了可追溯的距离。 Conversely, if I remove the queryString from the trades list request it correctly returns the entire available trade history.
相反,如果我从交易列表请求中删除queryString,它将正确返回整个可用交易历史记录。
So something about the http-conduit query string is obviously different. 因此,关于http-conduit查询字符串的内容显然有所不同。 Anyone know what it might be?
有人知道这可能是什么吗?
Here is the Haskell Request object being sent (as printed by "Show"): 这是发送的Haskell请求对象(如“显示”所示):
Request {
host = "data.mtgox.com"
port = 443
secure = True
clientCertificates = []
requestHeaders = []
path = "api/2/BTCUSD/money/trades/fetch"
queryString = "since=1367142721624293"
requestBody = RequestBodyLBS Empty
method = "GET"
proxy = Nothing
rawBody = False
redirectCount = 10
responseTimeout = Just 10000000
}
According to its returned headers Mt Gox is using cloudflare-nginx and PHP 5. 根据返回的标头,Mt Gox正在使用cloudflare-nginx和PHP 5。
Edit: Forgot to mention that when I use http-conduit to send a request with a queryString to http://scooterlabs.com/echo I get the correct response as well, so it seems to be some interaction between the Mt Gox webserver and http-conduit. 编辑:忘了提到,当我使用http-conduit将带有queryString的请求发送到http://scooterlabs.com/echo时,我也得到了正确的响应,因此似乎是Mt Gox网络服务器与HTTP的管道。
Got it figured out. 明白了。 You need to add a User-Agent string.
您需要添加用户代理字符串。 So
所以
requestHeaders = [(CI.mk "User-Agent", "Test/0.0.1")],
in the middle of the request function makes it work. 在request函数的中间使其起作用。
$ time curl https://data.mtgox.com/api/2/BTCUSD/money/trades/fetch?since=1367142721624293
...
real 0m20.993s
Looks to me like everything is working correctly: the API call takes a while to return, so http-conduit throws a timeout exception since 20s is longer than 10s. 在我看来,一切都工作正常:API调用需要一段时间才能返回,因此http-conduit会引发超时异常,因为20s大于10s。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.