簡體   English   中英

卷曲不適用於Content-Type

[英]Curl not working with Content-Type

我有以下代碼:

$input = http_build_query(array('text' => 'hello'));
$url = "http://localhost/deskline/server.php";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $input);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain', 'Content-Length:'.strlen($input)));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
$data = curl_exec($ch);
curl_close($ch);

echo $data;

在server.php文件中,此代碼為:

echo $_POST['text'];

每當我加載應該回顯文本(您好)的php文件時,除非我從標題中刪除“ Content-Type:text / plain”,否則什么都不會發生。 我嘗試使用插入的“ text / html”,但這根本沒有幫助。

我將非常感謝您的每條建議。

謝謝

我認為您需要添加一條額外的curl_setopt語句以使其成為POST請求。

添加以下內容:

curl_setopt($ ch,CURLOPT_POST,1);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM