u011199303
-nimabi
采纳率0%
2017-07-12 03:34 阅读 1.5k

java使用httpclient向百度的收录入口提交URL报 403错误

package com.galaxy.promotion.baidu;

import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

public class Test {
public static void main(String[] args) throws HttpException, IOException {
HttpClient httpclient = new HttpClient();
// 创建post方法实例
PostMethod postMethod = new PostMethod("http://zhanzhang.baidu.com/linksubmit/urlsubmit");

    // 填入各个表单域的值
    NameValuePair[] data = { new NameValuePair("url", "www.example.com") };

    // 将表单的值放入到post方法中
    postMethod.setRequestBody(data);
    // 执行post方法
    int statusCode = httpclient.executeMethod(postMethod);
    System.out.println(statusCode);
    System.out.println(postMethod.getStatusLine());
}

}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • qq_16259463 疯雪 2017-07-12 05:16

    是不是依赖一些请求头

    点赞 评论 复制链接分享

相关推荐