Code example for DefaultHttpClient

Methods: execute, getCookieStore, getCredentialsProvider, setCookieStore

0
		ClientConnectionManager cm = new SingleClientConnManager(params,
				schemeRegistry);
		int connection_Timeout = GlobalVar.getInstance().getConnectionTimeout();
		HttpConnectionParams.setConnectionTimeout(params, connection_Timeout);
		HttpConnectionParams.setSoTimeout(params, connection_Timeout);
		DefaultHttpClient httpClient = new DefaultHttpClient(cm, params);
		httpClient.getCredentialsProvider().setCredentials(
				new AuthScope(null, -1),
				new UsernamePasswordCredentials(user, passwd));
 
		HttpResponse response = null;
		Log.d("Barcode", "doPost " + json);
//		Log.d("Barcode", "user: " + user + " password: " + passwd); 
//		Log.d("Barcode",GlobalVar.getInstance().getCookie().toString()); 
 
		if (GlobalVar.getInstance().getCookie() != null) { 
			CookieStore store = new BasicCookieStore();
			store.addCookie(GlobalVar.getInstance().getCookie());
			httpClient.setCookieStore(store);
		} 
		 
//		if(!preferences.getString("cookie", "").equals("")){ 
////			List<Cookie> cookies = httpClient.getCookieStore().getCookies(); 
////			Editor editor = preferences.edit(); 
////			editor.putString("cookie", cookies.get(0).toString()); 
//			CookieStore store = new BasicCookieStore(); 
//			store.addCookie(preferences.getString("cookie", "")); 
//			httpClient.setCookieStore(store); 
//		} 
		 
 
		try { 
			response = httpClient.execute(createRequest(json, serverorclient,
					ipaddress, port));
		} catch (ClientProtocolException e) {
			Log.d("Barcode","clientprot");
			e.printStackTrace();
			return null; 
		} catch (UnsupportedEncodingException e) {
			Log.d("Barcode","unsupportedenc");
			e.printStackTrace();
			return null; 
		} catch (IOException e) {
			if (e.toString().contains("Read timed out")){
				GlobalVar.getInstance().setError("Timeout reached! Set a higher value for Timeout in Settingsscreen!"); 
				Log.d("Barcode",GlobalVar.getInstance().getError());
			}else{ 
				GlobalVar.getInstance().setError(e.toString());
				Log.d("Barcode",GlobalVar.getInstance().getError());
			} 
			 
			 
//			GlobalVar.getInstance().setCookie(null); 
			e.printStackTrace();
			return null; 
		} 
//		if (GlobalVar.getInstance().getCookie() == null) { 
			List<Cookie> cookies = httpClient.getCookieStore().getCookies();
			GlobalVar.getInstance().setCookie(cookies.get(0));
			Log.d("Barcode", "" + cookies.get(0));
//		} 
//		if(preferences.getString("cookie", "").equals("")){ 
//			List<Cookie> cookies = httpClient.getCookieStore().getCookies();