我想通過PHP使用curl發佈到WordPress - 默認情況下,我使用內置到WordPress的XMLRPC發佈。WordPress的XMLRPC返回空白,但成功
以下代碼發送成功,但沒有返回。我需要知道關於帖子的一些信息,比如它的URL - 如果我有'帖子ID',通過查看xmlrpc.php文件,它應該返回,我可以這樣做。下面是我對郵政代碼:
function post($username, $password, $title, $content, $url, $category=array(), $keywords='', $type='Wordpress')
{
$encoding = 'UTF-8';
$title = htmlentities($title,ENT_NOQUOTES,$encoding);
$keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);
$reqparams = array(
'title'=>$title,
'description'=>$content,
'mt_allow_comments'=>0, // 1 to allow comments
'mt_allow_pings'=>0, // 1 to allow trackbacks
'post_type'=>'post',
'mt_keywords'=>$keywords,
'categories'=>$category
);
$params = array(0,$username,$password,$reqparams,true);
$request = xmlrpc_encode_request('metaWeblog.newPost',$params);
$ch = curl_init();
$fp = fopen('/home/*/public_html/file.txt', 'w+');
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_STDERR, $fp);
$results = curl_exec($ch);
echo '<pre>'.print_r($results, true).'</pre>';
curl_close($ch);
return $results;
}
的echo '<pre>'.print_r($re...
線只顯示<pre></pre>
。我已經SAVD捲曲的詳細輸出到一個文件,請在下面找到它(我已經出演了URL):
* About to connect() to www.*******.com port 80 (#0)
* Trying 87.106.55.179... * connected
* Connected to www.*******.com (87.*.*.179) port 80 (#0)
> POST /xmlrpc.php HTTP/1.1
Host: www.*******.com
Accept: */*
Content-Length: 1445
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue
< HTTP/1.1 100 Continue
* Operation timed out after 1000 milliseconds with 0 bytes received
* Closing connection #0
正如我所說,代碼沒有職位,但不返回任何結果。對不起,直言不諱,但我知道這將開始一個毫無意義的答案洪流。那麼,我是否應該期待一個帖子ID被退回,如果沒有,我怎樣才能輕鬆地將它退回?
謝謝
回答很久以前,似乎是一個毫無意義的答案只是發佈一個更無意義的鏈接。 -1 – Mike 2011-08-01 10:18:45