很抱歉,如果這真的很模糊,我是新來的cURL和API的交互。使用cURL與PHP的POST請求
目前我創建了一個URL,其中包含將要訪問API(點播程序)並使用給定ID在地址簿中顯示聯繫人所需的身份驗證詳細信息。
$auth_url = 'https://' . $apiemail .':' . $apipassword . '@api.dotmailer.com/v2/address-books/' . $listID .'/contacts';
哪個地方送我有點像這樣:
https://username:[email protected]/v2/address-books/listID/contacts
下面是從頁
<ApiContact>
<Id>1058905201</Id>
<Email>[email protected]</Email>
<OptInType>Unknown</OptInType>
<EmailType>Html</EmailType>
<DataFields i:nil="true"/>
<Status>Subscribed</Status>
</ApiContact>
</ArrayOfApiContact>
現在我需要一個變量POST到API的XML。我的變量是$useremail
我打算使用cURL來做到這一點我使用PHP並避免使用REST代替SOAP。
我完全陌生,但我有一些代碼不起作用,但嘿,我試過了!
// Authenticate
$auth_url = 'https://' . $apiemail .':' . $apipassword . '@api.dotmailer.com/v2/address-books/' . $listID .'/contacts';
// open connection
$ch = curl_init();
// set the URL
curl_setopt($ch,CURLOPT_URL, $auth_url);
curl_setopt($ch,CURLOPT_POST, $useremail);
// execute post
$result = curl_exec($ch);
// close connection
curl_close($ch);
我知道這是路要走,但:
- 這給我發來一個404頁的從我的API
- 我知道的地方我錯過了,將在此添加到
<email>
行動XML - 該文檔引用了我沒有提及的方法
PostAddressBookContacts()
,那麼這是何去何從?
對不起,如果這是模糊的。我感謝任何人的建議。
可能重複(http://stackoverflow.com/questions/28395/passing-post-values-with-curl) – 2014-09-11 13:47:15
所以你需要使用curl發佈xml或者只發郵件var? – 2014-09-11 13:48:08
@RakeshSharma我真的不確定,因爲API文檔沒有解釋,我不知道我會如何發現。我正在嘗試將新聯繫人添加到列表中。 PostAddressBookContacts()方法應該這樣做,但我不知道應該在哪裏引用它。 – user1486133 2014-09-11 13:50:37