我遇到了一個問題,使用file_get_contents()
。PHP無法POST與file_get_contents()內容超過1024個字符
我POST
表單數據使用file_get_contents()
遠程腳本和短形式(即$postdata < 1024
)工作正常,但是當我的形式的含量超過那些1024
字符($postdata > 1024
),然後file_get_contents()
與遠程腳本返回通信問題總是一個空字符串(不是假的)
並且遠程腳本沒有什麼問題,對於測試我甚至修改它只返回「OK」,但正如我所說的$postdata > 1024
- 我得到的回報只是一個空字符串(並且遠程腳本沒有做它應該做的事)
這裏是代碼:
$postvals = array(
'from' => 'Test <[email protected]>',
'to' => '[email protected],
'subject' => 'Test',
'body' => $mail_html_content
);
$postdata = http_build_query($postvals);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => array(
'Connection: close',
'Content-type: application/x-www-form-urlencoded',
'Content-Length: '.strlen($postdata),
'Custom-header: test'),
'content' => $postdata,
'timeout' => 40
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://test.com/script.php', false, $context, -1, 40000);
順便說一句我的服務器post_max_size
設置爲100M
phpinfo()
服務器不會報告任何1024
或1K值(除了log_errors_max_len 1024
)
,其中可以這個腳本的問題? (我不喜歡使用捲曲)
服務器上的'post_max_size'是無關緊要的 - 尋找其他問題。 – blue
它是同一臺機器 - 我正在測試不同的域 - 所以我知道post_max_size就足夠了;不幸的是,我已經在所有我能想到的地方尋找問題,並且也搜索了類似的問題,但沒有運氣:(所以我決定在這裏問一個問題作爲最後的手段 – Picard
嗯,我相信問題*可能*那麼你會分享一些服務器端代碼,'var_dump($ _ POST)'也可以提供幫助,並且檢查接收端錯誤日誌 – blue