fsockopen을 사용하여 원시 HTTP 호출에 문제가 있습니까?fsockopen을 사용하여 GET 쿼리 URL에 POST
POST /api/?action=report HTTP/1.1
Host: www.webhosting-performance.com
Content-Type: application/x-www-form-urlencoded
Conent-Length: 9
Connection: close
test=test
원격 스크립트는 var_dump ($ _ POST)가 비어 있다고 말합니다.
내 PHP 코드의 조각은 다음과 같습니다 : 당신은 기본적으로 그냥 오타가
if (ini_get('allow_url_fopen') > 0) {
$parts = parse_url($url);
$fp = fsockopen($parts['host'], isset($parts['port']) ? $parts['port'] : 80, $errno, $errstr, 30);
if (!$fp) throw new Exception("Problem with $url, $errstr");
$post_string = $post_fields ? http_build_query($post_fields) : '';
$out = ($post_string ? "POST " : "GET ") . $parts['path'] . ((isset($parts['query'])) ? "?" . $parts['query'] : false) ." HTTP/1.1\r\n"
. "Host: ". $parts['host'] ."\r\n"
. ($post_string ? "Content-Type: application/x-www-form-urlencoded\r\n" : false)
. "Conent-Length: ". strlen($post_string) ."\r\n"
. "Connection: close\r\n"
. "\r\n" . $post_string;
fwrite($fp, $out);
// ...
} else {
// use curl
}
다년간의 경험과 그런 잔소리없는 오타. 나는 이것을 풀기 위해 몇 시간 동안 앉아 있었다. 실수로 그 오타를 계속 복사했습니다. 다른 시간 동안 저를 구해 주셔서 감사합니다;) 환호 – tim
다른 질문은. 나는 고객의 플랫폼에서 확장 기능을 지원하지 않기 때문에 가능한 한 기본 언어로 처리하려고합니다. 이 함수는 allow_url_fopen이 비활성화되어 있으면 말풍선을 지원합니다. PEAR을 추가 할 수도 있습니다. – tim