2016-04-13 233 views
0

在其实况的fastbill API状态,使这个卷曲的请求,以接收信息:卷曲请求

curl -v -X POST \ 
–u {E-Mail-Adresse}:{API-Key} \ 
-H 'Content-Type: application/xml' \ 
-d '{xml body}' \ 
https://my.fastbill.com/api/1.0/api.php 

使用RestClient我试着翻译成像要求一个Ruby这样的:

我如何阅读: - 使用基本身份验证并在头中声明内容类型,向https://my.fastbill.com/api/1.0/api.php发出发布请求,是否正确?

现在,这将是RestClient这样的资源基础的要求:

首先,我验证:

resource = RestClient::Resource.new('https://my.fastbill.com/api/1.0/api.php', '[email protected]', 'API-KEY-XXXXX') 

其工作,并授权我。 然后把我的请求:

xml = '<?xml version="1.0" encoding="utf-8"?><FBAPI><SERVICE>customer.get</SERVICE><FILTER/></FBAPI>' 

resource.post xml, content_type: 'application/xml' 

它总是返回400,我不知道还能在这里做什么。

另外json如何在这里工作?

resource.post param1: 'value', content_type: 'json' 

会很明显。

回答

0

您可以使用Restclient :: Request.execute。 400错误通常表明该请求未被recipeint理解。这可能是由标题或畸形数据造成的。您可能需要添加接受标头。尝试下面

require 'rest_client' 

RestClient::Request.execute(
    method: :post, 
    :user => '[email protected]', 
    :password => 'pass123', 
    url: "https://example/user.json", 
    payload: { 'user' => { 'name' => 'John Doe', 'email' => '[email protected]'} }.to_json, 
    headers: {:content_type => :json, :accept => :json} 
) 

的例子可以找到的选项here

-2
$url="https://my.fastbill.com/api/1.0/api.php"; 
$curl = curl_init(); 
curl_setopt($curl,CURLOPT_URL, $url); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
$result = curl_exec($curl); 
curl_close($curl); 
print_r(json_decode($result)); 
+0

庵的详细列表...这是红宝石? – Pang

+0

为什么?你为什么要这么做? – Hamdan