Skip to main content.

[44] NP_TrackBackを最新の仕様にあわせる修正

tDiaryへのTrackBackができないと言う話を聞き、サポートにてメソッドはPOSTですよと注意を受けた。
うーーん、わかったようなわかんないような話。
だけど、対応できたみたい。
function sendPing(...)の後半部分
================
// create URL
if (!strstr($ping_url,'?')) $ping_url .= '?';
$theURL = $ping_url . '&title=' . urlencode($title);
$theURL = $theURL . '&url=' . urlencode($url);
$theURL = $theURL . '&excerpt=' . urlencode($excerpt);
$theURL = $theURL . '&blog_name=' . urlencode($blog_name);


// echo htmlspecialchars($theURL);

// send ping (= open URL and get data)
$fp = @fopen ($theURL, 'r');
if (!$fp) return 'Could not send ping ('.htmlspecialchars($theURL).')';
$result = '';
while (!feof ($fp)) {
$result .= fgets($fp, 4096);
}
fclose($fp);
================
を、丸ごと以下のソースに取り替えます。
================
$URL = parse_url($ping_url); // URLを分解

/* クエリー */
if (isset($URL['query'])) {
$URL['query'] = "?".$URL['query'];
} else {
$URL['query'] = "";
}

/* デフォルトのポートは80 */
if (!isset($URL['port'])) $URL['port'] = 80;

/* リクエストライン */
$request = "POST ".$URL['path'].$URL['query']." HTTP/1.0\r\n";

/* リクエストヘッダ */
$request .= "Host: ".$URL['host']."\r\n";
$request .= "User-Agent: PHP/".phpversion()."\r\n";

/* Basic認証用のヘッダ */
if (isset($URL['user']) && isset($URL['pass'])) {
$request .= "Authorization: Basic ".base64_encode($URL['user'].":".$URL['pass'])."\r\n";
}

/* 追加ヘッダ */
$request .= $headers;

/* POSTの時はヘッダを追加して末尾にURLエンコードしたデータを添付 */
$post[title] = $title;
$post[url] = $url;
$post[excerpt] = $excerpt;
$post[blog_name] = $blog_name;

while (list($name, $value) = each($post)) {
$POST[] = $name."=".urlencode($value);
}
$postdata = implode("&", $POST);
$request .= "Content-Type: application/x-www-form-urlencoded\r\n";
$request .= "Content-Length: ".strlen($postdata)."\r\n";
$request .= "\r\n";
$request .= $postdata;
$request .= "\r\n";

/* WEBサーバへ接続 */
$fp = fsockopen($URL['host'], $URL['port']);

/* 接続に失敗した時の処理 */
if (!$fp) {
die("ERROR\n");
}

/* 要求データ送信 */
fputs($fp, $request);

/* 応答データ受信 */
$response = "";
while (!feof($fp)) {
$response .= fgets($fp, 4096);
}

/* 接続を終了 */
fclose($fp);

/* ヘッダ部分とボディ部分を分離 */
$DATA = split("\r\n\r\n", $response, 2);
================

でもって、そのちょっと下の、
if (strstr($result,'<error>1</error>'))
を、
if (strstr($DATA[1],'<error>1</error>'))
と書き換え。

これでどうでしょう?

Comments

No comments yet

Add Comment

:

:
: