2017-04-21 54 views
0

我试图使用RESTClient实现这样做卷曲后轨,RESTClient实现通过二进制字体文件

卷曲-v -i -X POST -H 'X-API的成功秘诀:' -F字体= @ myraid .TTF APIURL

这是我迄今为止

response = RestClient::Request.execute(
     :method => :post, 
     :url => api_url, 
     :headers => {:content_type => 'multipart/form-data', :accept => 'application/json', :X_Api_Secret => "xxxxxxxxx"} 
    ) 

,直到我试图通过一个文件中像这样

response =RestClient::Request.execute(
     :method => :post, 
     :url => api_url, 
     :headers => {:content_type => 'multipart/form-data', :accept => 'application/json', :X_Api_Secret => "xxxxxxxxxx"}, 
     :upload => { 
     :file => File.new(params[:custom_font][:font].path, 'rb') 
     } 
    ) 

我这完美的作品T,然后似乎忽略我的头,我得到一个403错误,我也尝试了常规的休息客户端请求后像

响应= RestClient.post api_url,{:X_Api_Secret =>“XXXXXX”}

但是当我尝试引入数据文件时,它又一次崩溃。

任何帮助,指针或建议将不胜感激。

回答

0

好几天头撞后,我最终使用unirest,而不是更新到最新版本后,它直接工作。

response = Unirest.post api_key, 
    headers:{ 
    "X-Api-Secret" => "xxxxx" 
    }, 
    parameters:{ 
    "data" => "ccc" 
    }