Project Address: Https://github.com/kevinsawicki/http-request
1, send a GET request , get the response code, easy enough.
Int code = httprequest.get ("http://google.com"). code ();
2, add a request parameter ? Can be added directly in the Get method, choose whether to encode, not accustomed to the map can also be used to pass the parameter oh.
HttpRequest request = Httprequest.get ("http://google.com", True, ' Q ', "Baseball gloves", "size", 100);
3, send a POST request with a file bar
HttpRequest request = httprequest.post ("url");
Request.header ("Content-type", "multipart/form-data;boundary=aab03x");
Request.part ("ImageFile", "Test.log", "Image/jpeg", New File ("d:/test/test.jpg"));
4, then send a post with form
map<string, string> data = new hashmap<string, string> ();
data.put ("User", "A user");
data.put ("state", "CA");
HttpRequest request = httprequest.post (URL). form (data);
5, send post with JSON
Jsonobject jsoncontent = new Jsonobject ();
Jsoncontent.addproperty ("Content", msgbody);
Jsonobject jsondata = new Jsonobject ();
Jsondata.add ("Data", jsoncontent);
Jsondata.addproperty ("subtype", subtype);
HttpRequest httprequest = httprequest.post (URL). Acceptjson ();
Httprequest.send (Jsondata.tostring ());
int code = Httprequest.code ();
String BODY = Httprequest.body ();
This open source implementation, the biggest feature is based on urlconnection implementation, do not rely on httpclient.
The entire project implementation only a Java class file, interested can see for themselves oh.
Httprequest,http's request weapon