首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用clj-http发布请求?

如何使用clj-http发布请求?
EN

Stack Overflow用户
提问于 2013-09-07 21:10:14
回答 2查看 6.1K关注 0票数 0

当我单击this页面上的搜索按钮时,它会发送一个post请求。我想通过cli-http来做这篇文章。我该怎么做呢?

代码语言:javascript
复制
(def default-http-opts 
    {:socket-timeout 10000
     :conn-timeout 10000
     :insecure? true
     :throw-entire-message? false})

(clj-http/post initial-url default-http-opts)

我可以发布一个请求,但问题是我想传入一些参数。这些参数(所选按钮)是页面上的默认参数。

它们是:

代码语言:javascript
复制
AdvancedSearchForm:CourseOrSubjectSelection=ALL_ALL
AdvancedSearchForm:GraduateLevelSelection=ALL

AdvancedSearchForm:allStudyAreas=t

AdvancedSearchForm:departmentList=

AdvancedSearchForm:facultyList=

AdvancedSearchForm:keywords=

AdvancedSearchForm:level=ALL

AdvancedSearchForm:semester=ALL

oracle.adf.faces.FORM=AdvancedSearchForm

oracle.adf.faces.STATE_TOKEN=_id21519:_id21520

source=AdvancedSearchForm:searchButton

键AdvancedSearchForm:semester包含':',所以我使用字符串作为键,比如"AdvancedSearchForm:semester",在clj-http中可以吗?

我是这样做的:

代码语言:javascript
复制
(spit (file "/tmp" "ts.html") 
    (:body (http/post initial-url 
        {:form-params {"AdvancedSearchForm:CourseOrSubjectSelection" "ALL_ALL",                          "AdvancedSearchForm:GraduateLevelSelection" "ALL"}})))`

实际上,它返回的页面确实是“结果”,但没有列出课程。仅模板。我想得到所有的课程链接,这只是手动点击显示。有什么帮助吗?

是我从篡改数据中截取的图像。它显示了我单击Search按钮后发生的事情。客户端似乎被重定向至searchresult.jsp。我使用curl来模仿它。我是这样做的

curl -D "form data..." https://handbook.unimelb.edu.au/faces/htdocs/user/search/AdvancedSearch.jsp

然后快速运行

curl https://handbook.unimelb.edu.au/faces/htdocs/user/search/SearchResults.jsp

下载页面后不会显示结果内容。

EN

回答 2

Stack Overflow用户

发布于 2013-09-08 18:09:20

看起来服务器不理解你发送给它的参数。

使用中的转义是percent-encoding。尝试使用clj-https README.md中提供的调试功能来检查它是否已投入使用:

代码语言:javascript
复制
;; print request info to *out*, including request body:
(client/post "http://example.org" {:debug true :debug-body true :body "..."})

或者尝试在终端中使用curl命令或使用方便的Firefox restclient add-on手动运行请求。

票数 2
EN

Stack Overflow用户

发布于 2013-09-07 21:22:26

从他们的GitHub页面(https://github.com/dakrone/clj-http):

代码语言:javascript
复制
;; Send form params as a urlencoded body (POST or PUT)
(client/post "http//site.com" {:form-params {:foo "bar"}})
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18673633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档