1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
public String sendPostHttpRequest(String url)
{
HttpConnection c = null;
DataInputStream dis = null;
DataOutputStream dos = null;
StringBuffer sb = new StringBuffer();
int rc;
String params = new String("");
try
{
c = (HttpConnection)Connector.open("http://<adresseServeur>/fichier.php");
c.setRequestMethod(HttpConnection.GET);
c.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
c.setRequestProperty("If-Modified-Since", "29 Oct 1999 19:43:31 GMT" );
c.setRequestProperty("Content-Language", "en-US" );
c.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.1");
//os = connection.openOutputStream();
dos = c.openDataOutputStream();
byte[] request_body = params.getBytes();
for( int i = 0; i < request_body.length; i++ )
{
dos.writeByte( request_body[i] );
}
dos.close();
}
catch (IOException e)
{
alert.setString("BUG");
_display.getDisplay(this).setCurrent(alert);
}
finally
{
try
{
if( c != null ) c.close();
if( dis != null ) dis.close();
if( dos != null ) dos.close();
}
catch ( IOException ioe )
{
ioe.printStackTrace();
}
}
return ("Connexion réussie");
} |
Partager