使用Java HttpClient 4.4登录Instagram

时间:2015-05-19 22:37:48

标签: java http cookies httpclient

在我的项目上取得了一些进展,但遇到了错误。我正在尝试使用HttpClient登录Instagram发送帖子参数到表单,但基本上每次我尝试访问网页时都会得到这个:

This page could not be loaded. If you have cookies disabled in your browser, or you are browsing in Private Mode, please try enabling cookies or turning off Private Mode, and then retrying your action.

代码如下:

    RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.BEST_MATCH).build();
    CookieStore cookieStore = new BasicCookieStore();
    HttpClientContext context = HttpClientContext.create();
    context.setCookieStore(cookieStore);
    CloseableHttpClient client = HttpClients.custom().setDefaultRequestConfig(globalConfig).setDefaultCookieStore(cookieStore).build();

更新:我用这个作为参考 https://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientFormLogin.java

但我仍然像以前一样遇到同样的问题。它似乎正在获取饼干?

Login form get: HTTP/1.1 403 FORBIDDEN
Post logon cookies:
- [version: 0][name: csrftoken][value: 85186441706764e44d9efeb6fb14acdd]   [domain: instagram.com][path: /][expiry: Wed May 18 18:05:50 EDT 2016]

0 个答案:

没有答案