2016-09-09 190 views
-2

我有這個代碼,可以通過shell使用,但支持告訴我,它也可以在php中用作http請求。你能告訴我如何?通過PHP的http請求

  curl --include \ 
    --request DELETE \ 
    --header "Authorization: Basic NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj" \ 
https://onesignal.com/api/v1/notifications/{notificationId}?app_id={appId} 

謝謝

+0

如手動說:http://php.net/manual/de/curl.examples.php – Najzero

+0

@Najzero我不知道如何發送「刪除」請求 – Tony33

+0

使用此作爲指導http://stackoverflow.com/questions/13420952/php-curl-delete-request –

回答

1

好了,我看你用蠟籠爭論不少,但還沒有你,我和我的評論友好的,所以這裏去。

#1需要的功能/ API您嘗試使用,使用shortways和StackOverflow上編寫代碼的一些基本的瞭解不會好起來:-)

的捲曲和Web和PHP庫,它的SETOPT ():

$curl = curl_init($url . "/Contacts/{$recordId}"); 
$curl = curl_init($url . "/Contacts/{$recordId}"); 
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); 
curl_setopt($curl, CURLOPT_HEADER, false); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json',"OAuth-Token: $token")); 

// Make the REST call, returning the result 
$response = curl_exec($curl); 
if (!$response) { 
    die("Connection Failure.n"); 
} 

(來自https://developer.sugarcrm.com/2013/08/30/doing-put-and-delete-with-curl-in-php/兩者)​​

請查找OAuth令牌文件,而是從運去那裏,我強烈地想你的哈希值。

+0

非常感謝你 – Tony33

0

我更喜歡file_get_contents()更多。

$arrContextOptions["http"] = array(
    "method" => "DELETE", 
    "header" => "Authorization: Basic NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj\r\nContent-type: application/json", 
    "content" => "", 
    "ignore_errors" => true 
); 

$response = file_get_contents("https://onesignal.com/api/v1/notifications/{notificationId}?app_id={appId}", false, stream_context_create($arrContextOptions)));