NutzCN Logo
精华 一个百度提交的小工具,正在使用
发布于 1096天前 作者 fangoxyz 675 次浏览 复制 上一个帖子 下一个帖子
标签:

package com.nutztools.utils;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;

public class SEOPing {
public static final String BAIDU_RPC = "http://data.zz.baidu.com/urls?site=www.f8fm.com&token=xxx";
//public static final String GOOGLE_RPC = "http://blogsearch.google.com/ping/RPC2";
public static final String PING_TITLE = "xxxxxxx"; /**博客名称**/
public static final String PING_URL = "http://www.f8fm.com/"; /**博客首页地址**/
//public static final String PING_RSS = "http://www.f8fm.com/rss.xml"; /**博客RSS地址**/
public static final String PING_RSS = ""; /**博客RSS地址**/

private static String buildMethodCall(String title, String url,
       String shareURL, String rssURL) {
    StringBuffer buffer = new StringBuffer();
    buffer.append(shareURL); 
    return buffer.toString();
}

public static String pingBaidu(String title, String url, String shareURL,
       String rssURL) throws Exception {
    PostMethod post = new PostMethod(BAIDU_RPC);
    post.addRequestHeader("User-Agent", "curl/7.12.1");
    post.addRequestHeader("Content-Type", "text/plain");
    String methodCall = buildMethodCall(title, url, shareURL, rssURL);
    RequestEntity entity = new StringRequestEntity(methodCall, "text/plain",
         "utf-8");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    // httpclient.getHostConfiguration().setProxy("127.0.0.1", 8888);
    httpclient.executeMethod(post);
    String ret = post.getResponseBodyAsString();
    post.releaseConnection();
    return ret;
}


public static void main(String[] args) throws Exception {
    String ret = SEOPing.pingBaidu(PING_TITLE, PING_URL,
         "http://www.f8fm.com/newsdetail/72.html",
         PING_RSS);
    System.out.println(ret);

    if (ret.contains("success")){
       System.out.println("百度提交正常");
    }
    //ret = SEOPing.pingGoogle(PING_TITLE, PING_URL,
    //     "http://www.f8fm.com/newsdetail/72.html",
    //     PING_RSS);
    //System.out.println(ret);
}

}

添加回复
请先登陆
回到顶部