HttpURLConnection und Proxy

Status
Nicht offen für weitere Antworten.

madmufflon

Mitglied
hey,
sorry erstmal, dass ich das thema aufmache, aber ich hab schon alle googleergebnisse abgegrast und nix hat geholfen. Also folgendes: ich hab ein programm, das über einen proxy ins internet soll. dazu brauch ich eine HttpURLConnection. leider muss dieses Programm hinter einem Proxy laufen. ich muss also eine HttpURLconnection machen, die über einen Proxy läuft. dazu hab ich 2 ansätze, beide verbinden sich zwar (mein computer ist hier auch so am internet) aber beide nicht über den proxy. der rest des programms läuft soweit.
1ster Ansatz:
Code:
System.setProperty("http.proxySet", "true");
                        System.setProperty("http.proxyHost", main.getProxy());
                        System.setProperty("http.proxyPort", String.valueOf(main.getProxyPort()));
                        
                        System.out.println(System.getProperty("http.proxyHost"));
                        System.out.println(System.getProperty("http.proxyPort"));
                        
                        URL url = main.getURL();
                        
                        HttpURLConnection urlc;
                        urlc = (HttpURLConnection)(url.openConnection());
                        
                        urlc.setDoOutput(true);
                        
                        System.out.println(urlc.usingProxy());

Ergibt folgende Ausgabe:
Code:
127.0.0.1
3128
false
Funktioniert also nich. der proxyllog zeigt auch nichts an.

2ter Ansatz:
Code:
URL url = main.getURL();
                        
                        HttpURLConnection urlc;
                        Proxy pr;
                        int port = main.getProxyPort();
                        if(port < 1) {
                            port = 80;
                        }
                        InetAddress ip = Inet4Address.getByName(main.getProxy());
                        InetSocketAddress sa = new InetSocketAddress(ip,port);
                                    
                        pr = new Proxy(Proxy.Type.HTTP, sa);
                        urlc = (HttpURLConnection)(url.openConnection(pr));
                        
                        urlc.setDoOutput(true);
                        
                        System.out.println(urlc.usingProxy());
Ergibt:
false

funktioniert also beides nicht, hat irgendwer einen rat?
danke schonmal
martin
 

madmufflon

Mitglied
hab es jetzt auch nochmal so versucht:
Code:
HttpClient httpclient = new HttpClient();
        
       [b] httpclient.getHostConfiguration().setProxy(main.getProxy(), main.getProxyPort());[/b]

        PostMethod method = new PostMethod(url.toExternalForm());
        method.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE,
                    false);
        try {
            Part[] parts = {
                new FilePart(main.getFilename(), file.getName(), file)
            };
            method.setRequestEntity(
                new MultipartRequestEntity(parts, method.getParams())
                );
            httpclient.getHttpConnectionManager().
                getParams().setConnectionTimeout(5000);
            int status = httpclient.executeMethod(method);
            if (status == HttpStatus.SC_OK) {
                System.out.println(
                    "Upload complete, response=" + method.getResponseBodyAsString()
                );
            } else {
                System.out.println(
                    "Upload failed, response=" + HttpStatus.getStatusText(status)
                );
            }
        } catch (Exception ex) {
            System.out.println("ERROR: " + ex.getClass().getName() + " "+ ex.getMessage());
            ex.printStackTrace();
        } finally {
            method.releaseConnection();
        }
In den Proxyprotokollen taucht er trotzdem nicht auf, aber der request wird erfolgreich versendet.
ich versteh das nicht...
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
T Brauche Hilfe beim GET-String für HttpURLConnection Netzwerkprogrammierung 4
E HttpUrlConnection Cookie Problem Netzwerkprogrammierung 0
V Unterschied zwischen cURL und HttpURLConnection?? Netzwerkprogrammierung 2
E HTTP HttpURLConnection & Javascript Netzwerkprogrammierung 2
A HTTP HttpURLConnection wiederverwenden? Netzwerkprogrammierung 2
T HttpURLConnection Netzwerkprogrammierung 6
T Ladezeit einer Seite mit HttpURLConnection und Bildern Netzwerkprogrammierung 2
J HttpURLConnection ResponseCode 403 Netzwerkprogrammierung 2
R HTTP HttpURLConnection Large File Upload Netzwerkprogrammierung 1
S HttpURLConnection POST splittet Daten in zwei Pakete Netzwerkprogrammierung 9
D Hilfe, meine HttpURLConnection hängt manchmal. Netzwerkprogrammierung 9
F HttpURLConnection überschreiben Netzwerkprogrammierung 2
W Problem mit HttpURLConnection Netzwerkprogrammierung 2
W HttpURLConnection-Wikipedia Netzwerkprogrammierung 15
E Multi-Part Form-Daten mit HttpURLConnection Netzwerkprogrammierung 6
M HttpUrlConnection + Client/Server Problem Netzwerkprogrammierung 2
X mehrere Request über eine HttpURLConnection Netzwerkprogrammierung 2
S Probleme mit HttpURLConnection Netzwerkprogrammierung 10
G Redirects einer HttpURLConnection ermitteln Netzwerkprogrammierung 4
Dann07 Proxy funktioniert nicht so wie gewünscht! Netzwerkprogrammierung 18
T Proxy mit Zusatzfunktion Netzwerkprogrammierung 1
J FTP Upload über Proxy funktioniert nicht Netzwerkprogrammierung 1
J FTP FTP Zugriff über Proxy Server Netzwerkprogrammierung 1
M Proxy und HTTPS Netzwerkprogrammierung 3
C Proxy Server - Antwort auf welchem Port Netzwerkprogrammierung 1
M Socket 2x Proxy multithread-server mit Cross Verbindung Netzwerkprogrammierung 0
N Proxy gibt keine Antwort zurück Netzwerkprogrammierung 5
M HTTP Reverse Proxy mit dynamischen Servern? Netzwerkprogrammierung 7
L Proxy für Dateidownload? Netzwerkprogrammierung 3
M Proxy Einstellungen auslesen Netzwerkprogrammierung 2
T Socket Java HTTP-Proxy Netzwerkprogrammierung 3
J HTTP Proxy nutzen Netzwerkprogrammierung 4
B Einfacher Proxy Server Netzwerkprogrammierung 29
M ganymed-ssh2.har: ftp-Verbindung über ftp-Proxy Netzwerkprogrammierung 2
S Proxy Authentifizierung HtmlUnit Netzwerkprogrammierung 8
S Proxy Authentifizierung Netzwerkprogrammierung 3
G Java Client Proxy Skript Netzwerkprogrammierung 3
Dit_ UDP Verbindung durch Proxy Netzwerkprogrammierung 4
P Proxy für Anwendung setzten Netzwerkprogrammierung 3
A UCP Connection über Proxy möglich? Netzwerkprogrammierung 7
trash HTTP Internet Connection bei Proxy ?! Netzwerkprogrammierung 3
L Einfacher Proxy-Server Netzwerkprogrammierung 6
M FTP-Connection über FTP-Proxy Netzwerkprogrammierung 20
M Verbindung über Proxy// Problem mit Outputstream bei URLConn Netzwerkprogrammierung 5
alexpetri simpler Proxy geht nicht Netzwerkprogrammierung 7
G Proxy oder Forwarding? Netzwerkprogrammierung 16
R xml via SSL über Proxy Netzwerkprogrammierung 2
R URLConnection via Proxy mit Authentification Netzwerkprogrammierung 5
S URLConnection über Proxy Netzwerkprogrammierung 4
J RMI Fehler beim Proxy Netzwerkprogrammierung 2
H FTP Client mit Squid als Proxy Netzwerkprogrammierung 8
G Proxy und mehrere Verbindungen Netzwerkprogrammierung 4
W java ueber proxy verbinden Netzwerkprogrammierung 3
reibi Proxy macht Problem abeim URL-Aufruf Netzwerkprogrammierung 3
G HTTP Client :: Komme nicht über den Proxy Netzwerkprogrammierung 7
A HTTPS-Request via Proxy mit Konfigurationsskript Netzwerkprogrammierung 3
T Erstellung eines Proxy Netzwerkprogrammierung 11
R proxy für java anwendung angeben [resolved] Netzwerkprogrammierung 15
T Proxy will einfach nicht mein prog akzeptieren Netzwerkprogrammierung 3
F Proxy: HTTP- Verbindung Netzwerkprogrammierung 2
B Url aufruf über Proxy Netzwerkprogrammierung 2
G Probleme bei Proxy-Server! Netzwerkprogrammierung 5
I Fehlermeldung bei Verbindung über SOCKS Proxy Netzwerkprogrammierung 4

Ähnliche Java Themen

Neue Themen


Oben