public void sendAndReceive(HttpMessage msg, boolean isFollowRedirect) throws IOException {

		log.debug("sendAndReceive " + msg.getRequestHeader().getMethod() + " "
				+ msg.getRequestHeader().getURI() + " start");
		msg.setTimeSentMillis(System.currentTimeMillis());

		try {
			notifyRequestListeners(msg);
			if (!isFollowRedirect
					|| !(msg.getRequestHeader().getMethod().equalsIgnoreCase(HttpRequestHeader.POST) || msg
							.getRequestHeader().getMethod().equalsIgnoreCase(HttpRequestHeader.PUT))) {
				// ZAP: Reauthentication when sending a message from the perspective of a User
				sendAuthenticated(msg, isFollowRedirect);
				return;
			}

			// ZAP: Reauthentication when sending a message from the perspective of a User
			sendAuthenticated(msg, false);

			HttpMessage temp = msg.cloneAll();
			temp.setRequestingUser(getUser(msg));
			// POST/PUT method cannot be redirected by library. Need to follow by code

			// loop 1 time only because httpclient can handle redirect itself after first GET.
			for (int i = 0; i < 1
					&& (HttpStatusCode.isRedirection(temp.getResponseHeader().getStatusCode()) && temp
							.getResponseHeader().getStatusCode() != HttpStatusCode.NOT_MODIFIED); i++) {
				String location = temp.getResponseHeader().getHeader(HttpHeader.LOCATION);
				URI baseUri = temp.getRequestHeader().getURI();
				URI newLocation = new URI(baseUri, location, false);
				temp.getRequestHeader().setURI(newLocation);

				temp.getRequestHeader().setMethod(HttpRequestHeader.GET);
				temp.getRequestHeader().setHeader(HttpHeader.CONTENT_LENGTH, null);
				// ZAP: Reauthentication when sending a message from the perspective of a User
				sendAuthenticated(temp, true);
			}

			msg.setResponseHeader(temp.getResponseHeader());
			msg.setResponseBody(temp.getResponseBody());

		} finally {
			msg.setTimeElapsedMillis((int) (System.currentTimeMillis() - msg.getTimeSentMillis()));
			log.debug("sendAndReceive " + msg.getRequestHeader().getMethod() + " "
					+ msg.getRequestHeader().getURI() + " took " + msg.getTimeElapsedMillis());

			notifyResponseListeners(msg);
		}
	}
public void sendAndReceive ( HttpMessage msg , boolean isFollowRedirect ) throws IOException { log . debug ( "sendAndReceive " + msg . getRequestHeader ( ) . getMethod ( ) + " " + msg . getRequestHeader ( ) . getURI ( ) + " start" ) ; msg . setTimeSentMillis ( System . currentTimeMillis ( ) ) ; try { notifyRequestListeners ( msg ) ; if ( ! isFollowRedirect || ! ( msg . getRequestHeader ( ) . getMethod ( ) . equalsIgnoreCase ( HttpRequestHeader . POST ) || msg . getRequestHeader ( ) . getMethod ( ) . equalsIgnoreCase ( HttpRequestHeader . PUT ) ) ) { sendAuthenticated ( msg , isFollowRedirect ) ; return ; } sendAuthenticated ( msg , false ) ; HttpMessage temp = msg . cloneAll ( ) ; temp . setRequestingUser ( getUser ( msg ) ) ; for ( int i = 0 ; i < 1 && ( HttpStatusCode . isRedirection ( temp . getResponseHeader ( ) . getStatusCode ( ) ) && temp . getResponseHeader ( ) . getStatusCode ( ) != HttpStatusCode . NOT_MODIFIED ) ; i ++ ) { String location = temp . getResponseHeader ( ) . getHeader ( HttpHeader . LOCATION ) ; URI baseUri = temp . getRequestHeader ( ) . getURI ( ) ; URI newLocation = new URI ( baseUri , location , false ) ; temp . getRequestHeader ( ) . setURI ( newLocation ) ; temp . getRequestHeader ( ) . setMethod ( HttpRequestHeader . GET ) ; temp . getRequestHeader ( ) . setHeader ( HttpHeader . CONTENT_LENGTH , null ) ; sendAuthenticated ( temp , true ) ; } msg . setResponseHeader ( temp . getResponseHeader ( ) ) ; msg . setResponseBody ( temp . getResponseBody ( ) ) ; } finally { msg . setTimeElapsedMillis ( ( int ) ( System . currentTimeMillis ( ) - msg . getTimeSentMillis ( ) ) ) ; log . debug ( "sendAndReceive " + msg . getRequestHeader ( ) . getMethod ( ) + " " + msg . getRequestHeader ( ) . getURI ( ) + " took " + msg . getTimeElapsedMillis ( ) ) ; notifyResponseListeners ( msg ) ; } }
Send and receive a HttpMessage.

@param msg
@param isFollowRedirect
@throws HttpException
@throws IOException
@see #sendAndReceive(HttpMessage, HttpRequestConfig)