gpt4 book ai didi

php - 使用 cURL 或 socket_create 发送自定义 HTTP POST 请求

转载 作者:太空宇宙 更新时间:2023-11-03 13:47:51 25 4
gpt4 key购买 nike

第一次接触stackoverflow。

我有一个问题。我尝试使用 fsockopen 发送此 HTTP 请求:

POST /cgi_dte/UPL/DTEUpload HTTP/1.0
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/ms-excel, application/msword, */*
Referer: {url}
Accept-Language: es-cl
Content-Type: multipart/form-data: boundary=9022632e1130lc4
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; PROG 1.0; Windows NT 5.0; YComp 5.0.2.4)
Content-Length: {lenght}
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: TOKEN={token}

--9022632e1130lc4
Content-Disposition: form-data; name="{ndata0}"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8Bit

{data}
--9022632e1130lc4
Content-Disposition: form-data; name="{ndata1}"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8Bit

{data}
--9022632e1130lc4
Content-Disposition: form-data; name="{ndata2}"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8Bit

{data}
--9022632e1130lc4
Content-Disposition: form-data; name="{ndata3}"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8Bit

{data}
--9022632e1130lc4
Content-Disposition: form-data; name="{filename}"; filename="{file.ext}"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary

{xml}

--9022632e1130lc4--

'

但 PHP 显示此消息:

Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /srv/http/modfe/sube_envio_y.php on line 81

Warning: fsockopen(): unable to connect to ssl://maullin.sii.cl:443 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /srv/http/modfe/sube_envio_y.php on line 81

PHP代码是:

$host = "ssl://{url}";
$port = 443;

$fp = fsockopen($host, $port, $errno, $errstr, 10);

if (!$fp) {
return false;
}
fputs($fp, $string); // <---- $string: the custom HTTP request
stream_set_timeout($fp, 20);
$data = "";
$status = socket_get_status($fp);
while(!feof($fp) && !$status['timed_out']) {
$data .= fgets($fp, 1024);
$status = socket_get_status($fp);
}
fclose($fp);

是否可以使用 cURL 或 socket_create() 创建并发送此请求?

php 中是否存在其他方法?

PD:我的英语不好。不好意思。

最佳答案

请注意 url 不应包含路径,因为唯一有效的值是主机,即 www.yourdomain.com。而不是像 www.yourdomain.com/1/demo.php 这样的东西

关于php - 使用 cURL 或 socket_create 发送自定义 HTTP POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27044822/

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