Hi,
also ich muss Daten die in meinem Midlet eingegeben wurde, per HTTP Post verschicken. In der Firma meinte einer das Get einfacher waere aber die URL laenge ja begrenzt ist, nur Post waere VIEL komplizierter. Nun hab ich mir einige Beispiele angesehen, und dort stand zb
Hat jemand Erfahrung mit HTTP Post? Und kann mir vllt sagen wie das nun ist mit diesem flush? Und wie schwer das nun wirklich ist?
also ich muss Daten die in meinem Midlet eingegeben wurde, per HTTP Post verschicken. In der Firma meinte einer das Get einfacher waere aber die URL laenge ja begrenzt ist, nur Post waere VIEL komplizierter. Nun hab ich mir einige Beispiele angesehen, und dort stand zb
Das steht in diesem Beispiel hier:/**Caution: os.flush() is controversial. It may create unexpected behavior
on certain mobile devices. Try it out for your mobile device **/
Code:
public void getBirthdayFromNameUsingPost(String name) throws IOException {
HttpConnection httpConn = null;
String url = "http://localhost:8080/examples/servlet/GetBirthday";
InputStream is = null;
OutputStream os = null;
try {
// Open an HTTP Connection object
httpConn = (HttpConnection)Connector.open(url);
// Setup HTTP Request to POST
httpConn.setRequestMethod(HttpConnection.POST);
httpConn.setRequestProperty("User-Agent",
"Profile/MIDP-1.0 Confirguration/CLDC-1.0");
httpConn.setRequestProperty("Accept_Language","en-US");
//Content-Type is must to pass parameters in POST Request
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
// This function retrieves the information of this connection
getConnectionInformation(httpConn);
os = httpConn.openOutputStream();
String params;
params = "name=" + name;
os.write(params.getBytes());
/**Caution: os.flush() is controversial. It may create unexpected behavior
on certain mobile devices. Try it out for your mobile device **/
//os.flush();
// Read Response from the Server
StringBuffer sb = new StringBuffer();
is = httpConn.openDataInputStream();
int chr;
while ((chr = is.read()) != -1)
sb.append((char) chr);
// Web Server just returns the birthday in mm/dd/yy format.
System.out.println(name+"'s Birthday is " + sb.toString());
} finally {
if(is!= null)
is.close();
if(os != null)
os.close();
if(httpConn != null)
httpConn.close();
}
}
Hat jemand Erfahrung mit HTTP Post? Und kann mir vllt sagen wie das nun ist mit diesem flush? Und wie schwer das nun wirklich ist?