【问题标题】:PHP function to connect to pingomatic using cURL使用 cURL 连接到 pingomatic 的 PHP 函数
【发布时间】:2010-09-09 07:33:46
【问题描述】:

我正在创建一个 PHP 函数来使用 CURL 连接到 pingomatic,但响应总是如此。

Array ( [EXE] => XML-RPC server accepts POST requests only. )

这是我的示例代码...

function curl_getpage2($url,$data, $referer = null, $agent = null, $header = null, $timeout = 20, $proxy = null, $proxy_username = null, $proxy_password = null) {
 //getProxy();
 if ($agent == null) {
     $agent = getAgent();
 }

 if ($referer == null) {
     $referer = getHost($url);
 }
 if (!is_array($header)) { 
  $header = array("Content-Type:text/xml","Host:".getHost($url),"User-Agent:$agent",
   "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
   "Accept-Language:en-us,en;q=0.5",
   "Accept-Encoding:gzip,deflate",
   "Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.7",
   "Keep-Alive:300",
   "Connection:keep-alive",
   "Cache-Control:max-age=0",
   "Content-length: ".strlen($XML));
 }

 if($proxy == null){
     $proxy = "208.100.27.155:60099";
 }

 if($proxy_username == null && $proxy_password == null){
     $proxyUnPW = "unproxy:pwproxy";
 }else{
     $proxyUnPW = $proxy_username.":".$proxy_password;
 }

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_HEADER, 0);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
 curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
 curl_setopt($ch, CURLOPT_PROXY, $proxy);
 curl_setopt($ch, CURLOPT_PROXYUSERPWD,$proxyUnPW);
        curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);

        //curl_setopt($ch, CURLOPT_USERAGENT, $agent);
 //curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        //curl_setopt($ch, CURLOPT_REFERER, $referer);
 //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
 //curl_setopt($ch, CURLOPT_AUTOREFERER,TRUE);
 //curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
 //curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookies.txt');
 //curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookies.txt');
 //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);       
 //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

        $result['EXE'] = curl_exec($ch);
        //$result['INF'] = curl_getinfo($ch);
        //$result['ERR'] = curl_error($ch);

        curl_close($ch);

        return $result;
}

我需要一些帮助。我只是对 PHP 有点陌生。

【问题讨论】:

  • 您的问题是什么?您的示例代码无法按您的意愿运行怎么办?
  • 能否用$data的内容和其他变量显示调用这个函数的代码。
  • $XML 中包含的内容strlen($XML)) 放入strlen($data))。也许你应该从标题中删除Content-length

标签: php proxy curl


【解决方案1】:

您可以通过网络表单提交您的网站一次,然后对该网址调用 GET 请求(请参阅 问题How to ping automatically to pingomatic in PHP?)。

因此,如果您想 ping 所有服务(标题和 url 用 urlencode() 编码),您的 URL 将类似于以下内容:

$url = 'http://pingomatic.com/ping/?title='.$title.'&blogurl='.$url.'&rssurl=&chk_weblogscom=on&chk_blogs=on&chk_feedburner=on&chk_newsgator=on&chk_myyahoo=on&chk_pubsubcom=on&chk_blogdigger=on&chk_weblogalot=on&chk_newsisfree=on&chk_topicexchange=on&chk_google=on&chk_tailrank=on&chk_skygrid=on&chk_collecta=on&chk_superfeedr=on');

例如:

http://pingomatic.com/ping/?title=Example%20Title&blogurl=http%3A%2F%2Fwww.example.com%2F&rssurl=&chk_weblogscom=on&chk_blogs=on&chk_feedburner=on&chk_newsgator=on&chk_myyahoo=on&chk_pubsubcom=on&chk_blogdigger=on&chk_weblogalot=on&chk_newsisfree=on&chk_topicexchange=on&chk_google=on&chk_tailrank=on&chk_skygrid=on&chk_collecta=on&chk_superfeedr=on

【讨论】:

    猜你喜欢
    • 2013-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-09
    • 1970-01-01
    • 1970-01-01
    • 2017-10-19
    • 1970-01-01
    相关资源
    最近更新 更多