Hallo an alle,
Ich möchte über meine App daten an einen php-Webservice senden. Ich weiß das Android es nicht erlaubt netzwerk funktionen im GUI Thread zu senden. Also habe ich mir einen Thread erstellt. Nun sendent er die Daten aber nicht. Fehler HttpHostConnectException: Connection to 127.0.0.1 refused ???
Mein Code ist dieser
Hier mal der Bericht aus LogCat
Ich möchte über meine App daten an einen php-Webservice senden. Ich weiß das Android es nicht erlaubt netzwerk funktionen im GUI Thread zu senden. Also habe ich mir einen Thread erstellt. Nun sendent er die Daten aber nicht. Fehler HttpHostConnectException: Connection to 127.0.0.1 refused ???
Mein Code ist dieser
Java-Quellcode
- // Registrierungs Daten mit Post senden
- public void register()
- {
- Thread t = new Thread(new Runnable(){
- @Override
- public void run() {
- // TODO Auto-generated method stub
- sendData();
- }
- });
- t.start();
- }
- public void sendData()
- {
- try {
- System.out.println("Starte senden");
- HttpClient client = new DefaultHttpClient();
- HttpPost post = new HttpPost("http://localhost/php/test/register.php");
- List<NameValuePair> postlist = new ArrayList<NameValuePair>();
- postlist.add(new BasicNameValuePair("user", this.username.getText().toString()));
- postlist.add(new BasicNameValuePair("mail", this.mail.getText().toString()));
- postlist.add(new BasicNameValuePair("pw5", this.kennwort.getText().toString()));
- post.setEntity(new UrlEncodedFormEntity(postlist));
- HttpResponse response = client.execute(post);
- System.out.println(response);
- this.b.setText("Fertig !");
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
Hier mal der Bericht aus LogCat
03-06 14:07:28.326: I/System.out(2282): Starte senden
03-06 14:07:29.086: W/System.err(2282): org.apache.http.conn.HttpHostConnectException: Connection to localhost refused
03-06 14:07:29.096: W/System.err(2282): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
03-06 14:07:29.106: W/System.err(2282): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
03-06 14:07:29.168: W/System.err(2282): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
03-06 14:07:29.187: W/System.err(2282): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
03-06 14:07:29.187: W/System.err(2282): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
03-06 14:07:29.196: W/System.err(2282): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
03-06 14:07:29.206: W/System.err(2282): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
03-06 14:07:29.206: W/System.err(2282): at com.example.musikapp.MainActivity.sendData(MainActivity.java:193)
03-06 14:07:29.226: W/System.err(2282): at com.example.musikapp.MainActivity$1.run(MainActivity.java:172)
03-06 14:07:29.226: W/System.err(2282): at java.lang.Thread.run(Thread.java:841)
03-06 14:07:29.226: W/System.err(2282): Caused by: java.net.ConnectException: failed to connect to /127.0.0.1 (port 80): connect failed: ECONNREFUSED (Connection refused)
03-06 14:07:29.246: W/System.err(2282): at libcore.io.IoBridge.connect(IoBridge.java:114)
03-06 14:07:29.258: W/System.err(2282): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
03-06 14:07:29.266: W/System.err(2282): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
03-06 14:07:29.356: W/System.err(2282): at java.net.Socket.connect(Socket.java:842)
03-06 14:07:29.356: W/System.err(2282): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
03-06 14:07:29.376: W/System.err(2282): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
03-06 14:07:29.376: W/System.err(2282): ... 9 more
03-06 14:07:29.396: W/System.err(2282): Caused by: libcore.io.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
03-06 14:07:29.396: W/System.err(2282): at libcore.io.Posix.connect(Native Method)
03-06 14:07:29.428: W/System.err(2282): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
03-06 14:07:29.428: W/System.err(2282): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
03-06 14:07:29.436: W/System.err(2282): at libcore.io.IoBridge.connect(IoBridge.java:112)
03-06 14:07:29.436: W/System.err(2282): ... 14 more