我知道您可以使用CURLOPT_port指定端口号,但是服务器托管在端口号后面的目录中。如果cURL无法实现这一点,有没有一种方法可以让我将表单数据POST为我上面指定的URL格式?请帮忙。
是的,您只需要指定CURLOPT_PORT
并在url中省略端口,如:
<?php
$post = [
'field' => 'value',
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://192.168.1.30/server');
curl_setopt($ch,CURLOPT_PORT, 8080);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
$response = curl_exec($ch);
if ($response === false) {
throw new RuntimeException(curl_error($ch));
}
var_export($response);