通过PHP

时间:2016-09-09 11:37:00

标签: php http request

我有这个代码,可以通过shell使用,但支持告诉我它也可以在php中用作http请求。你能告诉我怎么样吗?

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

谢谢

2 个答案:

答案 0 :(得分:1)

好吧,我看到你和蜡笼争论了很多,但是你和我以及我的评论都很友好,所以就这样了。

Stackoverflow需要对您尝试使用的函数/ api有一些基本的了解,使用shortways和stackoverflow来编写代码并不会很好: - )

对于CURL以及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令牌文档,但我强烈猜测来自操作系统的哈希就在那里。

答案 1 :(得分:0)

我更喜欢 file_get_contents()

awk -v start=2 -v len=3 \
   'FNR==NR{data[FNR]=substr($0, start, len); next}             # store from the start-th to the (start+len)-th chars
    {$0=substr($0, 1, start) data[FNR] substr($0, start+len+1)} # replace those
    1' f2 f1                                                    # print what was created