我有使用ColdFusion和CFHTTP工作調用的API如下:cURL相當於cfhttpparam?
<cfhttp url="http://api.domain.com/api/proxy.cfc" method="post" result="httpResult" charset="UTF-8">
<cfhttpparam type="url" name="method" value="apiauth"/>
<cfhttpparam type="url" name="argumentCollection" value="#jsData#"/>
</cfhttp>
的#jsData#是表示數據的陣列的JSON字符串。
什麼我在與我們的
<cfhttpparam type="url" name="method" value="apiauth"/>
使用捲曲的問題。如果我把它附加到網址爲:
http://api.domain.com/api/proxy.cfc?method=apiauth
我得到的迴應:暫時移動
在PHP中,我創建了數組作爲$ remoteArray 302(和數據工作正常,那麼問題是不是有),我已經試過這是我的捲毛:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://api.domain.com/api/proxy.cfc',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
'method' => 'apiauth',
'argumentCollection' => json_encode($remoteArray)
)
));
$resp = curl_exec($curl);
,但它不工作(可能是因爲方法=> apiauth不是後場 - 這是一個URL參數:param - 但我得到一個302如果我真的把它放在URL中。
已解決 - $ remoteArray 確實有錯誤。最初$ apiauthkey,$ apicomponent和$ apimethod是在數組外部定義的。一旦他們被添加到數組中的JSON編碼它的工作。這裏的房子$ remoteArray建:
$remoteArray = array(
"apiauthkey" => "$apiauthkey",
"apicomponent" => "$apicomponent",
"apimethod" => "$apimethod",
"apiarguments" => array(
'address_1'=>"test 1",
'address_2'=>"test 2",
'city'=>"new york",
'email'=>"[email protected]",
'first_name'=>"test fname",
'last_name'=>"test lname",
'ph_num'=>"2155551212",
'state'=>"NY",
'zip'=>"90210",
'rbpid' => $rbpid,
)
);
一旦嵌套數組是正確設置它正常工作與捲曲。感謝那些迴應!
它可能需要'application/json'的'header'和'value =「#variables.jsData#」'body'作爲'cfhttpparam' – Jarede
你的json結構是什麼樣子?在我的一些認證調用中,我循環遍歷併爲每個參數創建一個''。你也可能想要在''中限定'type'參數。我打斷了一個我正在談論的例子,如果這會有所幫助的話......(而不是作爲一個正式的答案,請注意你)。 –
啊!你說對了。看到你所需要做的就是在這裏發佈,然後你就明白了。我自己做了一次或兩次:D。然後讓你的'答案'並將其標記爲解決:) –