首先,我以前从未真正使用过API,而且我从未在Haskell中使用过HTTP库。我不确定我在这里做错了什么,所以也许有人知道可以提供帮助。
我正在使用我能读到的内容:http://github.com/defunkt/gist/blob/master/gist.rb,即写入方法,写下这个:
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
据我所知,位置应该是新Gist的链接。但是,没有新的要点。我不确定我做错了什么。基本上没有Gist API的文档,我唯一可以假设的是我没有正确翻译Ruby。就像我说的那样,我以前从未真正使用过HTTP库。
感谢任何帮助。
答案 0 :(得分:1)
在阅读使用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
答案 1 :(得分:0)
您的POST网址错误,根据来源应为http://gist.github.com/gists source