简体   繁体   English

在Ruby中编写curl调用

[英]Writing a curl Post call in Ruby

If i issue a POST request using curl command to github api to add "Resolved" label; 如果我使用curl命令向github api发出POST请求,以添加“已解决”标签; things are good. 事情很好。

curl -i -H "Authorization: token xxxxxxxxxxxx" -X POST 'https://git.corp.yahoo.com/api/v3/repos/owner/repo/issues/1/labels' -d '["Resolved"]'}

But when i try to do the same using Curl easy in my Ruby script 但是当我尝试在Ruby脚本中使用Curl easy进行相同操作时

 set gh_api = https://git.corp.yahoo.com/api/v3/repos/owner/repo/issues/1/labels
 curl = Curl::Easy.http_post(settings.gh_api,'["Resolved"]') 
 do |c|
    c.headers = ["Authorization: token xxxxxxxx"]
 end

The JSON reponse I get is 我得到的JSON响应是

"{\"message\":\"Not Found\"}"

What am i doing wrong in my ruby script? 我在ruby脚本中做错了什么?

It's not at all clear what question you are asking because there is no question. 根本不知道您要问什么问题,因为没有问题。

What's returned is a JSON response. 返回的是JSON响应。 Why don't you parse it with the JSON class and see what it returns: 为什么不使用JSON类解析它,并查看返回的结果:

require 'json'

puts JSON["{\"message\":\"Not Found\"}"]
=> {"message"=>"Not Found"}

I'm guessing that the problem is in the path of the URL if the response is "Not Found". 我猜测如果响应为“未找到”,则问题出在URL的路径中。

My URL was wrong. 我的网址有误。 I ended the URL with a '/'. 我以“ /”结尾URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM