php - CURL:主机名和端口后的路径
问题描述
我想在 PHP 中使用 curl将 JSON 数据发送到http://localhost:3000/certificates
这是我所做的:
$url = 'http://localhost';
$ch = curl_init($url);
$jsonData = array(
'certno' => 'AB1234',
'issueDate' => 'asdasd',
'type' => 'asdasdasd'
);
$jsonDataEncoded = json_encode($jsonData);
curl_setopt($ch, CURLOPT_PORT, 3000);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$result = curl_exec($ch);
如何添加 /certificates ?我不能简单地将它放在 url http://localhost/certificates中,对吗?
解决方案
推荐阅读
- c# - AuthorizationFilterAttribute 中未命中断点
- python-3.x - 应该定义的变量给了我 NameErrors,我该如何解决?
- linux - 加载共享库时出错:libssl.so.10:无法在 Docker 中打开共享对象文件
- c# - 排除某些项目使用 Directory.Build.props
- php - PHP Require 方法不显示任何 CSS 样式
- javascript - 函数钩子useEffect中的无限循环问题
- python - ImportError:没有名为站点的模块 - mac
- java - 了解为什么执行某些位操作操作
- curl - 在 PowerBi 中使用 cURL
- angular - 处理完所有文件后,我最后得到未定义错误的 id