jakarta httpclient: funktioniert nicht mit proxy

Status
Nicht offen für weitere Antworten.

jollyroger

Bekanntes Mitglied
Hallo,

nachdem der letzte Thread unbeantwortet blieb (Thema: Proxy mit HttpUrlConnection funktionierte nicht) hab ich mich entschlossen (auch aus anderen Gründen) den http-client von jakarta einzusetzen.

Leider klappt es auch hier nicht mit dem Proxy....

So sieht ein Verbindungsaufbau mit dem http-client aus:

Code:
	protected String sendRequest(String urlParams) {

		String answer = null;
	
		HttpClient httpClient = new HttpClient();
		
		if(networkParams.isUseProxy()) {
			httpClient.getHostConfiguration().setProxy(networkParams.getProxyHost(), networkParams.getProxyPort());
			logger.info("we DO use a proxy: host:" + networkParams.getProxyHost() + "Port: " + new Integer(networkParams.getProxyPort()).toString());
		}
		if(networkParams.isUseProxyCredentials()) {
			httpClient.getState().setProxyCredentials(
							new AuthScope(networkParams.getProxyHost(), networkParams.getProxyPort()),
							new UsernamePasswordCredentials(networkParams.getProxyUserName(), networkParams.getProxyUserPassword()));
		}
		
		String url = networkParams.getRemoteProtocoll() + 
					  networkParams.getRemoteDestinationAdress() + 
					  ":" + 
					  networkParams.getRemoteDestinationPort() + 
					  networkParams.getRemoteDestinationPath();
		
		HttpMethod method = new PostMethod(url);
		method.setQueryString(urlParams);
	
		try {
			int statusCode = httpClient.executeMethod(method);
			if (statusCode != HttpStatus.SC_OK) {
				logger.error(OutputConstants.ERR_WRONG_RESPONSE + CommonOutput.LOG_SPACER + statusCode);
				return null;
			}
			answer = method.getResponseBodyAsString();
		} catch (HttpException e) {
			logger.error(e.getMessage());
			logger.error(e);
			return null;
		} catch (IOException e) {
			logger.error(e.getMessage());
			logger.error(e);
			return null;
		}
		finally {	
			method.releaseConnection();
		}
		return answer;
	}

Das klappt auch alles soweit, wenn ich eben keinen Proxy angebe.

Gebe ich aber einen an, erhalt ich durch diese Logzeile:

Code:
		if (statusCode != HttpStatus.SC_OK) {
				logger.error(OutputConstants.ERR_WRONG_RESPONSE + CommonOutput.LOG_SPACER + statusCode);
				return null;
			}

die Meldung:

Code:
ERR_WRONG_RESPONSE -> 403

was ja "access forbidden" heisst.

Tja, nun verstehe ich nicht warum. Gebe ich im firefox meinen (squid) proxy an, und rufe dann meine SSL-Testseite auf kommt die Zertifikatsabfrage und ich komme auf meine Testseite. Sprich squid + SSL funktionieren prinzipiell.
Nur aus dem http-client heraus nicht scheint es mir.

Nochmal kurz das Szenario:

Localhost : http-client -> proxy-server -> localhost : apache mit https

Jemand ne Idee?
 
Hast du es schon mal mit einer HTTP- (nicht HTTPS-) Verbindung versucht? Dann wäre zumindest klar, ob es generell an der Verbindung über das Proxy liegt, oder ob das Problem nur bei SSL-Kommunikation besteht.
 
Hi,

ich bin auch der Honk vor dem Herrn, was ich nicht bedacht hatte war, das squid (mein proxy) tatsächlich in der Default-Einstellung nur Verbindungen von localhost zulässt...

Problem erledigt.......🙂
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben