duangu3620
2014-08-20 21:09
浏览 70
已采纳

如何用PHP中的CGI服务器作为客户端进行通信?

With PHP I need to send a request to a CGI server, and then to receive the respective response. What I have done so far seems right until the moment of trying to read the response:

<?php
$request_body = '-----------------9022632e1130lc4
';
$request_body .= 'Content-Disposition: form-data; name="rutSender"
';
...
$request_body .= '</EnvioDTE>
';
$request_body .= '
';
$request_body .= '-----------------9022632e1130lc4--
';

$request = 'POST /cgi_dte/UPL/DTEUpload HTTP/1.0
';
$request .= 'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/ms-excel, application/msword, */*
';
...
$request .= '
';
$request .= $request_body;

$hostName = 'host.name.example';
$host = gethostbyname($hostName);
$port = 443;

$fp = fsockopen($hostName, $port);
fwrite($fp, $request);

Below I try to read the response, but I receive "Fatal error: Maximum execution time of 120 seconds exceeded":

while(!feof($fp)){
    echo fgets($fp, 1024);
}
?>

As I am novice working with this kind of communication methods, it seems to me that in the PHP world exist way many options to try for solving this ploblem, like diverse socket functions, extensions and libraries (not that I have not tryed for 4 days)... I am confused and need orientation.

Regards

1条回答 默认 最新

相关推荐 更多相似问题