Android php Datei

mafiamix

Mitglied
Hallo,

ich möchte mit folgendem Code:

Code:
public static void saveData(String args) {
        try {
            URL url = new URL("http://localhost/datalog.php");
            phpConnect con = new phpConnect(url);
            try {
                con.send(args);
                System.out.println(con.read());
            } catch (IOException e) {
                e.printStackTrace();
            } 
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
Code:
saveDataphp("coords&provider="+provider);

eine php-Datei aufrufen.
In der phpConnect steht folgendes:

Code:
package gui.panel;

import gui.UserGUI;


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;

public class phpConnect {


private URL sitepath;

private URLConnection con;

public phpConnect() {

}

public phpConnect(URL sitepath) {
this.sitepath = sitepath;
}


public void setSitePath(URL sitepath) {
this.sitepath = sitepath;
}

public URL getSitePath() {
return this.sitepath;
}

public void send(String data) throws IOException {
if (con == null) {
con = sitepath.openConnection();
}
if (con.getDoOutput() == false) {
con.setDoOutput(true);
}
OutputStream out = con.getOutputStream();
out.write(data.getBytes());
out.flush();
}

public String read() throws IOException {
if (con == null) {
con = sitepath.openConnection();
}
InputStream in = con.getInputStream();
int c = 0;
StringBuffer incoming = new StringBuffer();
while (c >= 0) {
c = in.read();
incoming.append((char) c);
}
return incoming.toString();
}

}

Allerdings scheint die php-Datei nicht aufgerufen zu werden. Wo liegt denn der Fehler? Rufe ich die php-Datei manuell auf, dann funktioniert alles ohne Probleme und die Daten werden gespeichert. Über Java allerdings nicht.
 
Nachtrag:

Was passiert, wenn du diese Zeile etwas umbaust:

Java:
URL url = new URL("http://localhost/datalog.php");

Zu
Java:
URL url = new URL("http://localhost/datalog.php?"+args);

Und diese Zeile entfernst:
Java:
            try {
                // con.send(args); << Wird nicht gebraucht
 
Zurück