Ok. š aljem kod funkcije koja koristi POST request...
Htio bi znati kako bi trebala izgledati php skripta koja uzima ovaj string "This is a post" i recimo npr. okreće ga i vraća ga natrag...
Znam da ima veze sa $_POST globalnom varijablom ali eto nisam uspio još...
))
[syntax="java"]
private String sendHttpPost( String url )
{
HttpConnection hcon = null;
DataInputStream dis = null;
DataOutputStream dos = null;
StringBuffer responseMessage = new StringBuffer();
// the request body
String requeststring = "This is a post";
try {
// an HttpConnection with both read and write access
hcon = ( HttpConnection )Connector.open( url, Connector.READ_WRITE );
// set the request method to POST
hcon.setRequestMethod( HttpConnection.POST );
// obtain DataOutputStream for sending the request string
dos = hcon.openDataOutputStream();
byte[] request_body = requeststring.getBytes();
// send request string to server
for( int i = 0; i < request_body.length; i++ ) {
dos.writeByte( request_body
);
}//end for( int i = 0; i < request_body.length; i++ )
// obtain DataInputStream for receiving server response
dis = new DataInputStream( hcon.openInputStream() );
// retrieve the response from server
int ch;
while( ( ch = dis.read() ) != -1 ) {
responseMessage.append( (char)ch );
}//end while( ( ch = dis.read() ) != -1 ) {
}
catch( Exception e )
{
e.printStackTrace();
responseMessage.append( e.toString() );
}
finally {
// free up i/o streams and http connection
try {
if( hcon != null ) hcon.close();
if( dis != null ) dis.close();
if( dos != null ) dos.close();
} catch ( IOException ioe ) {
ioe.printStackTrace();
}//end try/catch
}//end try/catch/finally
return responseMessage.toString();
}//end sendHttpPost( String )
}
[/syntax]