自动提交站点最新文章到百度
如果个人拥有自己的站点,并且想把最近更新的文件提交到百度,参考 http://zhanzhang.baidu.com/linksubmit/index 。
官方没有给出java 示例,这里写了一个,测试通过。
import java.io.IOException;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public static String pushUrl(String url) { int timeout = 30; RequestConfig config = RequestConfig.custom() .setConnectTimeout(timeout * 1000) .setConnectionRequestTimeout(timeout * 1000) .setSocketTimeout(timeout * 1000).build(); CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(config).build(); HttpPost hp = new HttpPost("接口调用地址, 见: http://zhanzhang.baidu.com/linksubmit/index"); hp.setHeader("Host", "data.zz.baidu.com"); hp.setHeader("User-Agent", "curl/7.12.1"); hp.setHeader("Content-Type", "text/plain"); HttpResponse httpresponse; HttpEntity entity = null; try { StringEntity jsonEntity = new StringEntity(url, ContentType.TEXT_PLAIN); hp.setEntity(jsonEntity); httpresponse = httpClient.execute(hp); entity = httpresponse.getEntity(); String body = EntityUtils.toString(entity); return body; } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if(entity != null) try { entity.getContent().close(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } hp.releaseConnection(); } return null; }
1、 用到 httpclient 包。apache 站点可下载。
2、 StringEntity jsonEntity = new StringEntity(url, ContentType.TEXT_PLAIN);
hp.setEntity(jsonEntity);
实际是 http post Json 提交方法
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?