Hallo,
wenn ich Daten an ein PHP Script sende, und mir dieses irgendwelche Zeichen mit echo ausgibt, hängt folgendes Script immer ein ? an die Zeichenkette mit dran.
Ich vermute, dass es an/in der while-Schleife liegt, welche an incoming immer ein Char dranhängt...
Mein Quellcode:
Vllt. erkennt jemand das Problem auf anhieb? Ich komm nicht drauf...
Danke!
Gruß
wenn ich Daten an ein PHP Script sende, und mir dieses irgendwelche Zeichen mit echo ausgibt, hängt folgendes Script immer ein ? an die Zeichenkette mit dran.
Ich vermute, dass es an/in der while-Schleife liegt, welche an incoming immer ein Char dranhängt...
Mein Quellcode:
Java:
package de.tests;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class dbreadandwrite {
private URL sitepath;
private URLConnection con;
public dbreadandwrite(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 (this.con == null) {
this.con = this.sitepath.openConnection();
}
if (this.con.getDoOutput() == false) {
this.con.setDoOutput(true);
}
OutputStream out = this.con.getOutputStream();
out.write(data.getBytes());
out.flush();
}
public String read() throws IOException {
if (this.con == null) {
this.con = this.sitepath.openConnection();
}
InputStream in = this.con.getInputStream();
int c = 0;
StringBuffer incoming = new StringBuffer();
while (c >= 0) {
c = in.read();
incoming.append((char) c);
}
return incoming.toString();
}
public static void main(String[] args) {
try {
URL url = new URL("http://localhost/test.php");
dbreadandwrite con = new dbreadandwrite(url);
try {
con.send("foo=bar");
System.out.println(con.read());
} catch (IOException e) {
System.out.println(e);
}
} catch (MalformedURLException e) {
System.out.println(e);
}
}
}
Vllt. erkennt jemand das Problem auf anhieb? Ich komm nicht drauf...
Danke!
Gruß