为什么卷曲结果与抑制结果有区别?

时间:2014-08-08 01:37:51

标签: ruby curl web

如果我直接做curl命令,我可以得到以下结果。这就是我想要的。

(我根据我们的安全政策隐藏了确切的网址信息。)

C:\curl-7.34.0-devel-mingw32\bin>curl --data "action=search&user=wbt&project=Tes
t&ltoken=" http://xxx.xxx.xxx.xxx:8088/review/api

{"id":3,"status":"Fix","severity":"Error","severityCode":2,"state":"Existing","c
ode":"MLK.MUST","message":"Memory leak. Dynamic memory stored in \u0027new_cat\u
0027 allocated through function \u0027malloc\u0027 at line 11 is lost at line 31
","file":"/data001/tools/test/test.c","method":"main","owner":"unowned","taxonom
yName":"C and C++","url":"http://xxx.xxx.xxx.xxx:8088/review/insight-review.html
#goto:project\u003dTest,pid\u003d3"}
{"id":4,"status":"Analyze","severity":"Error","severityCode":2,"state":"Existing
","code":"MLK.MUST","message":"Memory leak. Dynamic memory stored in \u0027new_c
at2\u0027 allocated through function \u0027malloc\u0027 at line 12 is lost at li
ne 31","file":"/data001/tools/test/test.c","method":"main","owner":"unowned","ta
xonomyName":"C and C++","url":"http://xxx.xxx.xxx.xxx:8088/review/insight-review
.html#goto:project\u003dTest,pid\u003d4"}

但是,如果我使用如下所示的curb使用ruby脚本,结果似乎有所不同。

c = Curl::Easy.new
c.url = "http://xxx.xxx.xxx.xxx:8088/review/api?action=search&user=wbt&project=Test&ltoken="
c.perform
puts c.body_str

我刚收到服务器的web api帮助指南。 实际上,当我在ruby中使用net / http api时,我得到了相同的结果。

您能告诉我如何删除所需数据吗?

非常感谢。

1 个答案:

答案 0 :(得分:2)

使用--datacurl告诉curl HTTP POST数据,而你的路缘代码正在创建HTTP GET请求。

(在http://curl.haxx.se/docs/manpage.html搜索--data


尝试以下限制代码(改编自https://github.com/taf2/curb中的示例):

http = Curl.post("http://xxx.xxx.xxx.xxx:8088/review/api", {:action => "search", :user => "wbt", :project => "Test", :ltoken => ""})
puts http.body_str