public static String doGet(String strUrl ){
String strReturn="";
HttpGet httpGet = new HttpGet(strUrl);
CloseableHttpClient httpclient = null;
CloseableHttpResponse response1=null;
try {
httpclient = ();
response1 = (httpGet);
HttpEntity entity1 = ();
strReturn=(entity1) ;
(entity1);
}catch(Exception e){
();
}finally {
try {
if(response1!=null)
();
} catch (IOException e) {
();
}
}
return strReturn;
}
2、put
public static String doPut(String strUrl,String param){
CloseableHttpClient httpclient = ();
String strReturn="";
PutMethod httpput=new PutMethod(strUrl);
try {
if(param!=null)
{
RequestEntity entity = new StringRequestEntity(param, "application/json", "UTF-8");
(entity);
}
(httpput);
byte[] bytes = ();
strReturn= new String(bytes) ;
} catch (Exception e) {
// TODO Auto-generated catch block
();
}
return strReturn;
}
3、post
public static String doPost(String requestUrl, String payload) {
CloseableHttpClient httpclient = ();
String strReturn="";
PostMethod httpost = new PostMethod(requestUrl);
try {
if(payload!=null)
{
RequestEntity entity = new StringRequestEntity(payload, "application/json", "UTF-8");
(entity);
}
(httpost);
byte[] bytes = ();
strReturn= new String(bytes) ;
} catch (Exception e) {
// TODO Auto-generated catch block
();
}
return strReturn;
}
4、delete
public static void doDelete(String urlToRead) throws Exception {
URL url = new URL(urlToRead);
HttpURLConnection httpCon = (HttpURLConnection) ();
(true);
(
"Content-Type", "application/x-www-form-urlencoded" );
("DELETE");
();
();
}