如何在PHP中作为客户机与CGI服务器通信?
使用PHP,我需要向CGI服务器发送请求,然后接收相应的响应。到目前为止,我所做的似乎是正确的,直到尝试阅读回复的那一刻:如何在PHP中作为客户机与CGI服务器通信?,php,client-side,Php,Client Side,使用PHP,我需要向CGI服务器发送请求,然后接收相应的响应。到目前为止,我所做的似乎是正确的,直到尝试阅读回复的那一刻: <?php $request_body = '-----------------9022632e1130lc4\r\n'; $request_body .= 'Content-Disposition: form-data; name="rutSender"\r\n'; ... $request_body .= '</EnvioDTE>\r\n'; $req
<?php
$request_body = '-----------------9022632e1130lc4\r\n';
$request_body .= 'Content-Disposition: form-data; name="rutSender"\r\n';
...
$request_body .= '</EnvioDTE>\r\n';
$request_body .= '\r\n';
$request_body .= '-----------------9022632e1130lc4--\r\n';
$request = 'POST /cgi_dte/UPL/DTEUpload HTTP/1.0\r\n';
$request .= 'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/ms-excel, application/msword, */*\r\n';
...
$request .= '\r\n';
$request .= $request_body;
$hostName = 'host.name.example';
$host = gethostbyname($hostName);
$port = 443;
$fp = fsockopen($hostName, $port);
fwrite($fp, $request);
由于我是这类通信方法的新手,在我看来,在PHP世界中存在着许多解决这一问题的方法,比如各种套接字函数、扩展和库(我已经4天没有尝试过了)。。。我很困惑,需要定位
关于您需要在请求后添加两行换行符,而不仅仅是您现有的换行符。 请尝试将“\r\n”添加到请求的末尾
$request .= $request_body."\r\n";
顺便说一句,你不必为这些事操心。只需使用和张贴变得容易500%
$request .= $request_body."\r\n";