How does Java use HTTPclient to access url to obtain data

  • 2021-11-14 05:47:02
  • OfStack

Directory uses HTTPclient to access url to obtain data 1, uses get method to obtain data 2, uses POST method to obtain data and uses httpclient background to call url mode

Access url to get data using HTTPclient

Recently, there is a small function on the project that needs to call the http interface of the third party to get data, and HTTPclient is used, so it is a note!

1. Use get method to obtain data


/** 
 *  According to URL Trial get Method to get the returned data  
 * @param url 
 *        URL Address and parameters are directly hung in URL You can do it later  
 * @return 
 */  
public static String getGetDateByUrl(String url){  
    String data = null;  
    // Structure HttpClient Example of     
    HttpClient httpClient = new HttpClient();    
    // Create GET Example of method     
    GetMethod getMethod = new GetMethod(url);   
    // Set header information: If you do not set it User-Agent May report 405 As a result, data cannot be retrieved   
    getMethod.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:39.0) Gecko/20100101 Firefox/39.0");  
    // Use the default recovery policy provided by the system     
    getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());    
    try{  
        // Start execution getMethod    
        int statusCode = httpClient.executeMethod(getMethod);  
        if (statusCode != HttpStatus.SC_OK) {  
            System.err.println("Method failed:" + getMethod.getStatusLine());  
        }  
        // Read content   
        byte[] responseBody = getMethod.getResponseBody();  
        // Processing content   
        data = new String(responseBody);  
    }catch (HttpException e){  
        // An exception occurred, possibly because the protocol is incorrect or there is something wrong with the returned content   
        System.out.println("Please check your provided http address!");  
        data = "";  
        e.printStackTrace();  
    }catch(IOException e){  
        // A network exception occurred   
        data = "";  
        e.printStackTrace();  
    }finally{  
        // Release connection   
        getMethod.releaseConnection();  
    }  
    return data;  
}  

2. Use POST method to obtain data


/** 
 *  According to post Method to get the returned data  
 * @param url 
 *          URL Address  
 * @param array 
 *           Need to use post Parameters submitted in form  
 * @return 
 */  
public static String getPostDateByUrl(String url,Map<String ,String> array){  
    String data = null;  
    // Structure HttpClient Example of     
    HttpClient httpClient = new HttpClient();    
    // Create post Example of method     
    PostMethod postMethod = new PostMethod(url);   
    // Set header information   
    postMethod.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:39.0) Gecko/20100101 Firefox/39.0");  
    postMethod.addRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");  
    // Traversing to set the parameters to submit   
    Iterator it = array.entrySet().iterator();    
    while (it.hasNext()){  
        Map.Entry<String,String> entry =(Map.Entry) it.next();    
        String key = entry.getKey();    
        String value = entry.getValue().trim();    
        postMethod.setParameter(key,value);  
    }  
    // Use the default recovery policy provided by the system     
    postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());    
    try{  
        // Execute postMethod    
        int statusCode = httpClient.executeMethod(postMethod);  
        if (statusCode != HttpStatus.SC_OK) {  
            System.err.println("Method failed:" + postMethod.getStatusLine());  
        }  
        // Read content   
        byte[] responseBody = postMethod.getResponseBody();  
        // Processing content   
        data = new String(responseBody);  
    }catch (HttpException e){  
        // A fatal exception occurred, possibly because the protocol was wrong or there was something wrong with the returned content   
        System.out.println("Please check your provided http address!");  
        data = "";  
        e.printStackTrace();  
    }catch(IOException e){  
        // A network exception occurred   
        data = "";  
        e.printStackTrace();  
    }finally{  
        // Release connection   
        postMethod.releaseConnection();  
    }  
    System.out.println(data);  
    return data;  
}  

Use httpclient background to call url mode

When using httpclient to call the background, the parameters of url type need to be decoded by UrlDecoder, and when calling, the parameters need to be encoded by UrlEncoder, and then called.


@SuppressWarnings("deprecation")
	@RequestMapping(value = "/wechatSigns", produces = "application/json;charset=utf-8")
	@ResponseBody
	public String wechatSigns(HttpServletRequest request, String p6, String p13) {
		Map<String, String> ret = new HashMap<String, String>();
		try {
			System.out.println("*****************************************p6:"+p6);
			URLDecoder.decode(p13);
			System.out.println("*****************************************p13:"+p13);
			String p10 = "{\"p1\":\"1\",\"p2\":\"\",\"p6\":\"" + p6 + "\",\"p13\":\"" + p13 + "\"}";
			p10 = URLEncoder.encode(p10, "utf-8");
			String url = WebserviceUtil.getGetSignatureUrl() + "?p10=" + p10;
			String result = WebConnectionUtil.sendGetRequest(url);
			JSONObject fromObject = JSONObject.fromObject(URLDecoder.decode(result, "utf-8"));
			System.out.println(fromObject);
			String resultCode = JSONObject.fromObject(fromObject.getString("meta")).getString("result");
			if ("0".equals(resultCode)) {
				JSONObject fromObject2 = JSONObject.fromObject(fromObject.get("data"));
				String timestamp = fromObject2.getString("timestamp");
				String appId = fromObject2.getString("appId");
				String nonceStr = fromObject2.getString("nonceStr");
				String signature = fromObject2.getString("signature");
				ret.put("timestamp", timestamp);
				ret.put("appId", appId);
				ret.put("nonceStr", nonceStr);
				ret.put("signature", signature);
				JSONObject jo = JSONObject.fromObject(ret);
				return ResultJsonBean.success(jo.toString());
			} else {
				String resultMsg = JSONObject.fromObject(fromObject.getString("meta")).getString("errMsg");
				return ResultJsonBean.fail(ConnectOauthCodeInfo.REQ_WECHATTOCKEN_CODE, resultMsg, "");
			}
		} catch (Exception e) {
			logger.error(e, e);
			return ResultJsonBean.fail(ConnectOauthCodeInfo.REQ_WECHATREQERROE_CODE,
					ConnectOauthCodeInfo.REQ_WECHATREQERROE_CODE, "");
		}
	}

<pre name="code" class="java">package com.dcits.djk.core.util;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
 
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils; 
import net.sf.json.JSONObject;
 
public class WebConnectionUtil {	
	public static String sendPostRequest(String url,Map paramMap,String userId){
		CloseableHttpClient httpclient=null;
		CloseableHttpResponse response=null;		
		try{
			httpclient = HttpClients.createDefault();
			HttpPost httppost = new HttpPost(url);
			List<NameValuePair> formparams = new ArrayList<NameValuePair>();
			if(userId != null || "".equals(userId) ){
				formparams.add(new BasicNameValuePair("userId",userId));
			}
			Set keSet=paramMap.entrySet();
			for(Iterator itr=keSet.iterator();itr.hasNext();){
				Map.Entry me=(Map.Entry)itr.next();
				Object key=me.getKey();
				Object valueObj=me.getValue();
				String[] value=new String[1];
				if(valueObj == null){
					value[0] = "";
				}else{
					if(valueObj instanceof String[]){  
			            value=(String[])valueObj;  
			        }else{  
			            value[0]=valueObj.toString();  
			        }
				}
				for(int k=0;k<value.length;k++){  
					formparams.add(new BasicNameValuePair(key.toString(),StringUtil.filterSpecialChar(value[k])));
		        }
			}
			UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
			httppost.setEntity(uefEntity);
 
			response = httpclient.execute(httppost);
			if(response.getStatusLine().getStatusCode() == 200){
				HttpEntity entity = response.getEntity();
				String resultInfo = EntityUtils.toString(entity, "UTF-8");
				return resultInfo;
			}else{
				return response.getStatusLine().getStatusCode() + "";
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				if(httpclient != null){
					httpclient.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			try {
				if(response != null){
					response.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return "404";
	}
	
	public static String sendPostRequest(String url,Map paramMap){
		CloseableHttpClient httpclient=null;
		CloseableHttpResponse response=null;
		
		try{
			httpclient = HttpClients.createDefault();
			HttpPost httppost = new HttpPost(url);
			List<NameValuePair> formparams = new ArrayList<NameValuePair>();
			Set keSet=paramMap.entrySet();
			for(Iterator itr=keSet.iterator();itr.hasNext();){
				Map.Entry me=(Map.Entry)itr.next();
				Object key=me.getKey();
				Object valueObj=me.getValue();
				String[] value=new String[1];
				if(valueObj == null){
					value[0] = "";
				}else{
					if(valueObj instanceof String[]){  
			            value=(String[])valueObj;  
			        }else{  
			            value[0]=valueObj.toString();  
			        }
				}
				for(int k=0;k<value.length;k++){  
					formparams.add(new BasicNameValuePair(key.toString(),StringUtil.filterSpecialChar(value[k])));
		        }
			}
			UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
			httppost.setEntity(uefEntity);
 
			response = httpclient.execute(httppost);
			if(response.getStatusLine().getStatusCode() == 200){
				HttpEntity entity = response.getEntity();
				String resultInfo = EntityUtils.toString(entity, "UTF-8");
				return resultInfo;
			}else{
				return response.getStatusLine().getStatusCode() + "";
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				if(httpclient != null){
					httpclient.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			try {
				if(response != null){
					response.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return "404";
	}	
	
	public static String downloadFileToImgService(String remoteUtl,String imgUrl,String tempUrl){
		CloseableHttpClient httpclientRemote=null;
		CloseableHttpResponse responseRemote=null;		
		CloseableHttpClient httpclientImg=null;
		CloseableHttpResponse responseImg=null;		
		try{
			httpclientRemote = HttpClients.createDefault();
			HttpGet httpgetRemote = new HttpGet(remoteUtl);
			
			responseRemote = httpclientRemote.execute(httpgetRemote);
			if(responseRemote.getStatusLine().getStatusCode() != 200){
				return "";
			}
			HttpEntity resEntityRemote = responseRemote.getEntity();
			InputStream isRemote = resEntityRemote.getContent();
			// Write to a file 
			File file = null;
			
			boolean isDownSuccess = true;
			BufferedOutputStream bos = null;
			try{
				BufferedInputStream bif = new BufferedInputStream(isRemote);
				byte bf[] = new byte[28];
				bif.read(bf);
				String suffix = FileTypeUtil.getSuffix(bf);
				file = new File(tempUrl + "/" + UuidUtil.get32Uuid()+suffix);
				bos = new BufferedOutputStream(new FileOutputStream(file));
				if(!file.exists()){
					file.createNewFile();
				}
				bos.write(bf, 0, 28);
				byte b[] = new byte[1024*3];
				int len = 0;
				while((len=bif.read(b)) != -1){
					bos.write(b, 0, len);
				}
			}catch(Exception e){
				e.printStackTrace();
				isDownSuccess = false;
			}finally{
				try {
					if(bos != null){
						bos.close();
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			if(!isDownSuccess){
				return "";
			}
			
			httpclientImg = HttpClients.createDefault();
			HttpPost httpPostImg = new HttpPost(imgUrl);
			MultipartEntityBuilder requestEntity = MultipartEntityBuilder.create();
			requestEntity.addBinaryBody("userFile", file);
			
			HttpEntity httprequestImgEntity = requestEntity.build();
			httpPostImg.setEntity(httprequestImgEntity);
			responseImg = httpclientImg.execute(httpPostImg);
			if(responseImg.getStatusLine().getStatusCode() != 200){
				return "";
			}
			HttpEntity entity = responseImg.getEntity();
			String json = EntityUtils.toString(entity, "UTF-8");
			json = json.replaceAll("\"","");
			String[] jsonMap = json.split(",");
			String resultInfo = "";
			for(int i = 0;i < jsonMap.length;i++){
				String str = jsonMap[i];
				if(str.startsWith("url:")){
					resultInfo = str.substring(4);
				}else if(str.startsWith("{url:")){
					resultInfo = str.substring(5);
				}
			}
			if(resultInfo.endsWith("}")){
				resultInfo = resultInfo.substring(0,resultInfo.length()-1);
			}
			try{
				if(file != null){
					file.delete();
				}
			}catch(Exception e){
				e.printStackTrace();
			}
			return resultInfo;
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				if(httpclientRemote != null){
					httpclientRemote.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			try {
				if(responseRemote != null){
					responseRemote.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			try {
				if(httpclientImg != null){
					httpclientImg.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			try {
				if(responseImg != null){
					responseImg.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return "";
	}
	
	public static String downloadFileToImgService(File file,String imgUrl){
		CloseableHttpClient httpclientImg=null;
		CloseableHttpResponse responseImg=null;		
		try{
			httpclientImg = HttpClients.createDefault();
			HttpPost httpPostImg = new HttpPost(imgUrl);
			MultipartEntityBuilder requestEntity = MultipartEntityBuilder.create();
			requestEntity.addBinaryBody("userFile", file);
			
			HttpEntity httprequestImgEntity = requestEntity.build();
			httpPostImg.setEntity(httprequestImgEntity);
			responseImg = httpclientImg.execute(httpPostImg);
			if(responseImg.getStatusLine().getStatusCode() != 200){
				return "";
			}
			HttpEntity entity = responseImg.getEntity();
			String json = EntityUtils.toString(entity, "UTF-8");
			json = json.replaceAll("\"","");
			String[] jsonMap = json.split(",");
			String resultInfo = "";
			for(int i = 0;i < jsonMap.length;i++){
				String str = jsonMap[i];
				if(str.startsWith("url:")){
					resultInfo = str.substring(4);
				}else if(str.startsWith("{url:")){
					resultInfo = str.substring(5);
				}
			}
			if(resultInfo.endsWith("}")){
				resultInfo = resultInfo.substring(0,resultInfo.length()-1);
			}
			return resultInfo;
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				if(httpclientImg != null){
					httpclientImg.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			try {
				if(responseImg != null){
					responseImg.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return "";
	}
	
	public static String sendGetRequest(String url){
		CloseableHttpClient httpclient=null;
		CloseableHttpResponse response=null;
		try{
			httpclient = HttpClients.createDefault();
			HttpGet httpGet = new HttpGet(url);
 
			response = httpclient.execute(httpGet);
			if(response.getStatusLine().getStatusCode() == 200){
				HttpEntity entity = response.getEntity();
				String resultInfo = EntityUtils.toString(entity, "UTF-8");
				return resultInfo;
			}else{
				return response.getStatusLine().getStatusCode() + "";
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				if(httpclient != null){
					httpclient.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			try {
				if(response != null){
					response.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return "404";
	}
	
	public static String sendHttpsPostRequestUseStream(String url,String param){
		CloseableHttpClient httpclient=null;
		CloseableHttpResponse response=null;		
		try{
			SSLContext ctx = SSLContext.getInstance("TLS");
			X509TrustManager xtm = new X509TrustManager() {
				public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
					
				}
 
				public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
					
				}
 
				public X509Certificate[] getAcceptedIssuers() {
					return null;
				}
			};
			TrustManager[] tm = {xtm};
			ctx.init(null,tm,null);
			HostnameVerifier hv = new HostnameVerifier(){
				public boolean verify(String arg0, SSLSession arg1) {
					return true;
				}
			};
			httpclient = HttpClients.custom().setSSLHostnameVerifier(hv).setSSLContext(ctx).build();
			HttpPost httpPost = new HttpPost(url);
			StringEntity strEntity = new StringEntity(param,"utf-8");
			httpPost.setEntity(strEntity);
			
 			response = httpclient.execute(httpPost);
			if(response.getStatusLine().getStatusCode() == 200){
				HttpEntity entity = response.getEntity();
				String resultInfo = EntityUtils.toString(entity, "UTF-8");
				return resultInfo;
			}else{
				return response.getStatusLine().getStatusCode() + "";
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				if(httpclient != null){
					httpclient.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			try {
				if(response != null){
					response.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return "404";
	}
	
	public static String sendHttpsPostRequestUseStream(String url,Map paramMap){
		CloseableHttpClient httpclient=null;
		CloseableHttpResponse response=null;		
		try{
			SSLContext ctx = SSLContext.getInstance("TLS");
			X509TrustManager xtm = new X509TrustManager() {
				public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
					
				}
 
				public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
					
				}
 
				public X509Certificate[] getAcceptedIssuers() {
					return null;
				}
			};
			TrustManager[] tm = {xtm};
			ctx.init(null,tm,null);
			HostnameVerifier hv = new HostnameVerifier(){
				public boolean verify(String arg0, SSLSession arg1) {
					return true;
				}
			};
			httpclient = HttpClients.custom().setSSLHostnameVerifier(hv).setSSLContext(ctx).build();
			HttpPost httpPost = new HttpPost(url);
			List<NameValuePair> formparams = new ArrayList<NameValuePair>();
			Set keSet=paramMap.entrySet();
			for(Iterator itr=keSet.iterator();itr.hasNext();){
				Map.Entry me=(Map.Entry)itr.next();
				Object key=me.getKey();
				Object valueObj=me.getValue();
				String[] value=new String[1];
				if(valueObj == null){
					value[0] = "";
				}else{
					if(valueObj instanceof String[]){  
			            value=(String[])valueObj;  
			        }else{  
			            value[0]=valueObj.toString();  
			        }
				}
				for(int k=0;k<value.length;k++){  
					formparams.add(new BasicNameValuePair(key.toString(),StringUtil.filterSpecialChar(value[k])));
		        }
			}
			UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
			httpPost.setEntity(uefEntity);
			
 			response = httpclient.execute(httpPost);
			if(response.getStatusLine().getStatusCode() == 200){
				HttpEntity entity = response.getEntity();
				String resultInfo = EntityUtils.toString(entity, "UTF-8");
				return resultInfo;
			}else{
				return response.getStatusLine().getStatusCode() + "";
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				if(httpclient != null){
					httpclient.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			try {
				if(response != null){
					response.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return "404";
	}
	
	public static String sendHttpsGetRequestUseStream(String url){
		CloseableHttpClient httpclient=null;
		CloseableHttpResponse response=null;		
		try{
			SSLContext ctx = SSLContext.getInstance("TLS");
			X509TrustManager xtm = new X509TrustManager() {
				public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
					
				}
 
				public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
					
				}
 
				public X509Certificate[] getAcceptedIssuers() {
					return null;
				}
			};
			TrustManager[] tm = {xtm};
			ctx.init(null,tm,null);
			HostnameVerifier hv = new HostnameVerifier(){
				public boolean verify(String arg0, SSLSession arg1) {
					return true;
				}
			};
			httpclient = HttpClients.custom().setSSLHostnameVerifier(hv).setSSLContext(ctx).build();
			HttpGet httpGet = new HttpGet(url);
			
 			response = httpclient.execute(httpGet);
			if(response.getStatusLine().getStatusCode() == 200){
				HttpEntity entity = response.getEntity();
				String resultInfo = EntityUtils.toString(entity, "UTF-8");
				return resultInfo;
			}else{
				return response.getStatusLine().getStatusCode() + "";
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				if(httpclient != null){
					httpclient.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			try {
				if(response != null){
					response.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return "404";
	}
	
	public static String sendHttpsPostRequestUseStreamForYZL(String url,OauthToken param){
		CloseableHttpClient httpclient=null;
		CloseableHttpResponse response=null;		
		try{
			SSLContext ctx = SSLContext.getInstance("TLS");
			X509TrustManager xtm = new X509TrustManager() {
				public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
					
				}
 
				public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
					
				}
 
				public X509Certificate[] getAcceptedIssuers() {
					return null;
				}
			};
			TrustManager[] tm = {xtm};
			ctx.init(null,tm,null);
			HostnameVerifier hv = new HostnameVerifier(){
				public boolean verify(String arg0, SSLSession arg1) {
					return true;
				}
			};
			httpclient = HttpClients.custom().setSSLHostnameVerifier(hv).setSSLContext(ctx).build();
			HttpPost httpPost = new HttpPost(url);
			StringEntity strEntity = new StringEntity(param.toString(),"utf-8");
			httpPost.setEntity(strEntity);
			httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded");
			
 			response = httpclient.execute(httpPost);
			if(response.getStatusLine().getStatusCode() == 200){
				HttpEntity entity = response.getEntity();
				String resultInfo = EntityUtils.toString(entity, "UTF-8");
				return resultInfo;
			}else{
				return response.getStatusLine().getStatusCode() + "";
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				if(httpclient != null){
					httpclient.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			try {
				if(response != null){
					response.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return "404";
	}
}

Related articles: