public String sendPostHttpRequest(String url)
{
HttpConnection c = null;
DataInputStream dis = null;
InputStream is = null;
DataOutputStream dos = null;
OutputStream os = null;
StringBuffer sb = new StringBuffer();
int rc;
String params = new String("");
try
{
c = (HttpConnection)Connector.open(url, Connector.READ_WRITE);
c.setRequestMethod(HttpConnection.POST);
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");
c.setRequestProperty("Content-Type", "*/*");
os = c.openOutputStream();
dos = new DataOutputStream(os);
/*byte [] byteRequest = params.getBytes ();
for (int i = 0; i < byteRequest.length; i ++)
{
dos.writeByte (byteRequest [i]);
}*/
//byte[] request_body =params.getBytes();
//dos.write(request_body);
is = c.openInputStream();
dis = new DataInputStream(is);
/*dis = new DataInputStream(c.openInputStream());
while((rc = dis.read()) != -1)
{
sb.append( (char)rc );
}*/
}
catch (IOException e)
{
e.printStackTrace();
sb.append( "ERROR" );
}
finally
{
try
{
if( c != null ) c.close();
if( is != null ) is.close();
if( dis != null ) dis.close();
if( os != null ) os.close();
if( dos != null ) dos.close();
}
catch ( IOException ioe )
{
ioe.printStackTrace();
}
}
return (_textField1.getString());
}
Partager