开发者

which java http client library is easy to use for programmatically doing posts, setting cookies and maybe ajax?

开发者 https://www.devze.com 2023-01-04 17:07 出处:网络
which java http client library is easy to use for programmatically doing posts, setting cookies 开发者_Go百科and maybe ajax?Apache HTTP Component (HttpClient 4.0),

which java http client library is easy to use for programmatically doing posts, setting cookies 开发者_Go百科and maybe ajax?


Apache HTTP Component (HttpClient 4.0),

http://hc.apache.org/httpcomponents-client-4.0.1/index.html

Normally, I would just use HttpURLConnection but its cookie handling is too weak to simulate browser behavior.


You can use JdkRequest from jcabi-http (I'm a developer), which does all this work for you, decorating HttpURLConnection, firing HTTP requests and parsing responses, for example:

new JdkRequest("http://www.google.com")
  .header("Content-Type", "application/x-www-form-urlencoded")
  .body()
  .formParam("name", "John")
  .back()
  .method("POST")
  .fetch();

Read this blog post for more details: http://www.yegor256.com/2014/04/11/jcabi-http-intro.html


Async request like AJAX: http://hc.apache.org/httpcomponents-asyncclient-dev/

Sync request: http://hc.apache.org/httpcomponents-client-4.0.1/index.html

Cookies is A kind of Header. Add cookies like A Header:

"Cookie: COOKIE_1=231412;COOKIE_2=234124"
0

精彩评论

暂无评论...
验证码 换一张
取 消