【发布时间】:2015-01-18 14:56:40
【问题描述】:
我是第一次接触 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 显示此消息:
警告:fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /srv/http/modfe/sube_envio_y.php on line 81
警告:fsockopen(): 无法连接到 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:我的英语不好。对不起。
【问题讨论】: