亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP Curl 發布并獲得響應

PHP Curl 發布并獲得響應

PHP
喵喵時光機 2022-07-09 18:13:43
我有一個如下的shell代碼?!癱url -X POST -F '[email protected];type=text/plain' https://textomate.com/a/uploadMultiple ”此代碼將文件發送到 URL 并獲得以下響應。{  "countedFiles": [    {      "wordsNumber": 340,      "charsNumber": 2908,      "charsNoSpacesNumber": 2506,      "wordsNumberNN": 312,      "charsNumberNN": 2755,      "charsNoSpacesNumberNN": 2353,      "md5": null,      "fileName": "textomate-api.pdf",      "error": null    }  ],  "total": {    "wordsNumber": 340,    "charsNumber": 2908,    "charsNoSpacesNumber": 2506,    "wordsNumberNN": 312,    "charsNumberNN": 2755,    "charsNoSpacesNumberNN": 2353,    "md5": null  }}我想通過 PHP 發布一個文件并得到這個響應或只有“charsNoSpacesNumber”的值。你能幫我解決這個問題嗎?
查看完整描述

3 回答

?
慕桂英546537

TA貢獻1848條經驗 獲得超10個贊

更新的代碼如下,您可以在圖像中看到結果。

我想在我的網站上使用這個 API來計算文檔的字符數。我正在使用 Wordpress,API 提供者為我們提供了 3 個選項,Java、PHP (Wordpress) 和 Shell。他們有一些適用于 Wordpress 的東西,但我不知道如何使用它。

您可以從這里訪問所有文件。 https://github.com/zentaly/textomate-api 如果你看看那里,你可以獲得更多信息,也許你可以找到我更好的解決方案。

再次感謝您的支持,我很感激。

<?php


if(is_callable('curl_init')){ 

    echo "curl is active"; 

} else { 

    echo "curl is passive"; 

}



//Initialise the cURL var

$ch = curl_init();


//Get the response from cURL

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);


//Set the Url

curl_setopt($ch, CURLOPT_URL, 'https://textomate.com/a/uploadMultiple');

curl_setopt($ch, CURLOPT_VERBOSE, 2);

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_exec: var_dump(curl_errno($ch));

var_dump(curl_error($ch)); 




$path = 'textomate-api.pdf';

$file = curl_file_create($path, 'application/pdf', 'file');


//Create a POST array with the file in it

$postData = array(

    'file' => $file,

);

curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);


// Execute the request, decode the json into array

$response = curl_exec($ch);

var_dump($response);

$response = json_decode($ch);

var_dump($response['total']['charsNoSpacesNumber']);

var_dump($response);

var_dump(file_exists($path));

var_dump($file);


?>

http://img1.sycdn.imooc.com//62c955050001782c19160989.jpg

查看完整回答
反對 回復 2022-07-09
?
www說

TA貢獻1775條經驗 獲得超8個贊

這是我的代碼,我還分享了代碼和結果的圖像。我希望有足夠的信息。


<?php


if(is_callable('curl_init')){ 

    echo "curl is active"; 

} else { 

    echo "curl is passive"; 

}



//Initialise the cURL var

$ch = curl_init();


//Get the response from cURL

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);


//Set the Url

curl_setopt($ch, CURLOPT_URL, 'https://textomate.com/a/uploadMultiple');


$path = 'textomate-api.pdf';

$file = curl_file_create($path, 'application/pdf', 'file');


//Create a POST array with the file in it

$postData = array(

    'file' => $file,

);

curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);


// Execute the request, decode the json into array

$response = json_decode(curl_exec($ch), true);

var_dump($response['total']['charsNoSpacesNumber']);

var_dump($response);

var_dump(file_exists($path));


?>

http://img1.sycdn.imooc.com//62c955140001e73419130990.jpg

查看完整回答
反對 回復 2022-07-09
?
有只小跳蛙

TA貢獻1824條經驗 獲得超8個贊

你可以這樣做:


但請務必先檢查他們的 T&C,因為我不確定他們是否免費提供此類服務。


還要確保包括一些錯誤/異常處理。


<?php

//Initialise the cURL var

$ch = curl_init();


//Get the response from cURL

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);


//Set the Url

curl_setopt($ch, CURLOPT_URL, 'https://textomate.com/a/uploadMultiple');


$path = '/path/to/your/file.pdf';

$file = curl_file_create($path, 'application/pdf', 'file');


//Create a POST array with the file in it

$postData = array(

    'file' => $file,

);

curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);


// Execute the request, decode the json into array

$response = json_decode(curl_exec($ch), true);

var_dump($response['total']['charsNoSpacesNumber']);


查看完整回答
反對 回復 2022-07-09
  • 3 回答
  • 0 關注
  • 174 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號