gpt4 book ai didi

php - 如何在 Cakephp 中发起 https post 请求

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:51:34 24 4
gpt4 key购买 nike

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

感谢任何帮助。

谢谢。

最佳答案

你可以使用其中的任何一个

CAKPHP 套接字

// 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.

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);

JAVASCRIPT 如果你想在客户端完成

关于php - 如何在 Cakephp 中发起 https post 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4254645/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com