首先請注意,您必須發送POST
請求到pastebin.com API,而不是GET
。因此,請勿在輸入數據上使用urlencode()
!
要從頁面網址獲取原始粘貼網址,您有幾個選項。但最簡單的大概是:
$apiResonse = 'http://pastebin.com/ABC123';
$raw = str_replace('m/', 'm/raw.php?i=', $apiResponse);
最後,這裏是一個完整的例子:
<?php
$data = 'Hello World!';
$apiKey = 'xxxxxxx'; // get it from pastebin.com
$apiHost = 'http://pastebin.com/';
$postData = array(
'api_dev_key' => $apiKey, // your dev key
'api_option' => 'paste', // action to perform
'api_paste_code' => utf8_decode($data), // the paste text
);
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => "{$apiHost}api/api_post.php",
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => http_build_query($postData),
));
$result = curl_exec($ch); // on success, some string like 'http://pastebin.com/ABC123'
curl_close($ch);
if ($result) {
$pasteId = str_replace($apiHost, '', $result);
$rawLink = "{$apiHost}raw.php?i={$pasteId}";
echo "Created new paste.\r\n Paste ID:\t{$pasteId}\r\n Page Link:\t{$result}\r\n Raw Link:\t{$rawLink}\r\n";
}
運行上面的代碼,輸出:
c:\xampp\htdocs>php pastebin.php
Created new paste.
Paste ID: Bb8Ehaa7
Page Link: http://pastebin.com/Bb8Ehaa7
Raw Link: http://pastebin.com/raw.php?i=Bb8Ehaa7
沒有工作,仍然出來,而不原始數據。 – user1725113
參考:http://snag.gy/tmqN0.jpg – user1725113
但是你從哪裏得到'$ url_received_on_last_step'?我看不到您的代碼(來自所提供的圖片),您實際上已經獲取了收到的網址。 –