2016-04-13 231 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