如何在Cakephp中进行https发布请求

Jos*_*h R 4 php rest https post cakephp

我有要求应用程序必须通过HTTPS POST进行REST API调用.我是cakephp的新手.我在想是否可以使用httpsocket进行https调用.

我感谢任何帮助.

谢谢.

Ish*_*Ish 23

您可以使用其中任何一种

CAKEPHP SOCKET

// Use either of the following two:
App::import('Core', 'HttpSocket'); // Cake 1.x
App::uses('HttpSocket', 'Network/Http'); // Cake 2.x

$HttpSocket = new HttpSocket();
$results = $HttpSocket->post('www.somesite.com/add', array('name' => 'test', 'type' => 'user'));  
//$results contains what is returned from the post.
Run Code Online (Sandbox Code Playgroud)

CURL

$url = 'http://domain.com/get-post.php';
$fields = 'var1=value1&var2=value2';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
$result = curl_exec($ch);
curl_close($ch);
Run Code Online (Sandbox Code Playgroud)

JAVASCRIPT 如果你想在客户端做到这一点