Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Problem mit OutputStream bei URLConnection

Empfohlene Antworten

Veröffentlicht

Hey,

ich habe folgendes Problem:

ich mache eine URLConnection auf und will nun daten über nen proxy zum server schicken, aber leider klappt das nicht so wie es soll. Hier erstmal mein Code:


//mein code, im programm in irgendeiner funktion

urlconnection = getUrl();


      this.setHeaderAndFooter();


                DataOutputStream out = new DataOutputStream(urlconnection.getOutputStream());

                out.writeBytes("string=hallowelt");

                out.close();


                BufferedReader URLinput = new BufferedReader(

                new InputStreamReader(urlconnection.getInputStream()));


                URLinput.close();



                System.exit(0);




private void setHeaderAndFooter() throws IOException{


                urlconnection.addRequestProperty("Host", url.getHost());


                urlconnection.addRequestProperty("User-Agent","Mozilla/5.0 (Java/UploadVertretungsplan;)");

                urlconnection.addRequestProperty("Accept","text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");

                urlconnection.addRequestProperty("Accept-Language","en-us,en;q=0.5");

                urlconnection.addRequestProperty("Accept-Charset","ISO-8859-1,utf-8;q=0.7,*;q=0.7");

                urlconnection.addRequestProperty("Connection", "close");

                urlconnection.addRequestProperty("Content-Type","multipart/form-data; boundary=" + boundary);

        }




private URLConnection getUrl() throws IOException, UnknownHostException{


                        //Das ganze läuft immer noch über einen proxy

                        URLConnection 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 = url.openConnection(pr);


                        urlc.setDoOutput(true);


                        return urlc;

   }

(Das Programm macht so nich so richtig sinn, is zum testen) Sieht ja soweit aus wie in den verschiedenen Tutorials, die ich gefunden hab, funktioniert nur leider nicht. Beim Server kommt nämlich folgendes an:

POST /test/javaUpload.php HTTP/1.0

Host:localhost

User-Agent:Mozilla/5.0 (Java/UploadVertretungsplan;)

Accept:text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

Accept-Language:en-us,en;q=0.5

Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.7

Content-Type:multipart/form-data; boundary=wyqyygmppuujegjkifhzwlgrcqeugwwepzwyrhqz

Content-Length:16

Via:1.1 martin%3a3128 (squid/2.7.STABLE3)

X-Forwarded-For:127.0.0.1

Cache-Control:max-age=259200

Connection:keep-alive

Kann mir jemand sagen, warum das nicht richtig ankommt?

bin für jede hilfe dankbar

grüße

martin

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.