gpt4 book ai didi

http - 使用来自 Haskell 的 Github Gist API

转载 作者:可可西里 更新时间:2023-11-01 15:30:02 24 4
gpt4 key购买 nike

首先,我以前从未真正使用过 API,也从未使用过 Haskell 中的 HTTP 库。我不确定我在这里做错了什么,所以也许知道的人可以提供帮助。

我正在使用我能读到的内容:http://github.com/defunkt/gist/blob/master/gist.rb , 即 write 方法, 写这个:

req = postRequest "http://gist.github.com/gists/new"

testPost = simpleHTTP $ req {rqBody = urlEncodeVars
[("login", "Raynes"),
("token","<removed>"),
("file_ext[gistfile1]",".hs"),
("file_name[gistfile1]","testfile"),
("file_contents[gistfile1]","main = putStrLn \"Hello, world!\"")]}

运行时,testPost 给出以下输出:

Right HTTP/1.1 302 Found 
Server: nginx/0.7.61
Date: Sun, 29 Nov 2009 17:13:51 GMT
Content-Type: text/html; charset=utf-8
Connection: close
Status: 302 Found
Location: http://gist.github.com/gists/new
X-Runtime: 1ms
Content-Length: 98
Set-Cookie: _github_ses=BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%3D%3D--884981fc5aa85daf318eeff084d98e2cff92578f; path=/; expires=Wed, 01 Jan 2020 08:00:00 GMT; HttpOnly
Cache-Control: no-cache

据我所知,Location 应该是指向新 Gist 的链接。但是,没有制定新的 Gist。我不确定我做错了什么。 Gist API 基本上没有文档,我唯一可以假设的是我没有正确翻译 Ruby。正如我所说,我以前从未真正使用过 HTTP 库。

感谢任何帮助。

最佳答案

我在阅读了一个使用 Network.Browser.browse 的例子后自己想通了。

req = "http://gist.github.com/gists"

testPost = do
(uri, rsp) <- Network.Browser.browse $ do
setAllowRedirects True
request $ formToRequest $
Form POST (fromJust $ parseURI req)
[("file_ext[gistfile1]",".hs"),
("file_contents[gistfile1]","main = putStrLn \"Hello, world!\""),
("login","Raynes"),
("token","removed")]
return uri

关于http - 使用来自 Haskell 的 Github Gist API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1816092/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com