[請益] 不知道是哪邊問題(curl?php版本?json?)
想要用廠商的API,他的範例CreatCustomers.php
我自己的appserv2.5.10跑出來,"Data"都null (如下)
result:{"Data":null,"ErrorCode":2,"Message":"FAIL"}
https://www.videgree.com/Store/Customer.mvc/Index 點它登入可看到您新增的!
我試著echo()出curl_init()的結果,會是Resource id #2,
echo()出base64_encode()的結果的話,會是
eyAgICAgICAgIkN1c3RvbWVyTm8iIDogIjEiLCAgICAgICAgICAgICAgICAi
Q3VycmVudE5hbWUiIDogIualiuadseWfjiIgICAgfQ==
我猜想是不是因為appserv的php5.2.6的關係?
好像是curl_setopt()還是curl_exec()這部分跑完之後,
應該要出來有東西的$resulta沒有東西。
可否給我一個方向去try?感謝!
http://www.videgree.com/store/ApiExample.mvc/Index/CreateCustomer
---------------------------------------------------------------------------------
class Util
{
public static function Post($URL, $data) { //Initiate cURL request and send
back the result
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:
application/json'));
curl_setopt($ch, CURLOPT_URL, $URL);
// curl_setopt($ch, CURLOPT_USERAGENT, $this->_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
// curl_setopt($ch, CURLOPT_COOKIEFILE, $this->_cookie_file_path);
// curl_setopt($ch, CURLOPT_COOKIEJAR, $this->_cookie_file_path);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POST, 1);
$resulta = curl_exec($ch);
if (curl_errno($ch)) {
echo 'ch:' . $ch;
print curl_error($ch);
} else {
curl_close($ch);
}
return $resulta;
}
}
-------------------------------------------------------------------------------------
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.135.90.54
→
04/18 15:30, , 1F
04/18 15:30, 1F
→
04/18 15:32, , 2F
04/18 15:32, 2F
→
04/18 15:33, , 3F
04/18 15:33, 3F
→
04/18 15:34, , 4F
04/18 15:34, 4F
→
04/18 15:37, , 5F
04/18 15:37, 5F
→
04/18 15:38, , 6F
04/18 15:38, 6F
→
04/18 15:40, , 7F
04/18 15:40, 7F
→
04/18 15:40, , 8F
04/18 15:40, 8F
→
04/18 15:45, , 9F
04/18 15:45, 9F
→
04/18 15:46, , 10F
04/18 15:46, 10F
已處理完畢
現在廠商那邊的範例稍微修改過了,已經可以正常運作了
原因只是name寫錯了(也不是寫錯,是整個程式裡都重新命名但漏了這裡)
文內我貼上來發問的程式碼,本身是可以run正確的。
如果您是也是用這產品的,現在的範例程式下載下來使用沒問題。(對server端的
名稱改正了)
※ 編輯: ldwang 來自: 220.135.90.54 (04/29 11:34)
→
04/29 11:36, , 11F
04/29 11:36, 11F
PHP 近期熱門文章
PTT數位生活區 即時熱門文章