Form POST İşlemi
...
HttpConnection conn = null;
String url = "http://www.mysite.com/login.jsp";
String agent = "Mozilla/4.0";
String rawData = "userid=joe&password=guessme";
String type = "application/x-www-form-urlencoded";
String encodedData = encode( rawData ); // user-supplied
try {
conn = (HttpConnection) Connector.open( url );
conn.setRequestMethod( HttpConnection.POST );
conn.setRequestProperty( "User-Agent", agent );
conn.setRequestProperty( "Content-Type", type );
conn.setRequestProperty( "Content-Length",
encodedData.length() );
OutputStream os = conn.openOutputStream();
os.write( encodedData.getBytes() );
int rc = conn.getResponseCode();
... // process it
}
catch( IOException e ){
// handle the error here
}
...
HttpConnection conn = null;
String url = "http://www.mysite.com/login.jsp";
String agent = "Mozilla/4.0";
String rawData = "userid=joe&password=guessme";
String type = "application/x-www-form-urlencoded";
String encodedData = encode( rawData ); // user-supplied
try {
conn = (HttpConnection) Connector.open( url );
conn.setRequestMethod( HttpConnection.POST );
conn.setRequestProperty( "User-Agent", agent );
conn.setRequestProperty( "Content-Type", type );
conn.setRequestProperty( "Content-Length",
encodedData.length() );
OutputStream os = conn.openOutputStream();
os.write( encodedData.getBytes() );
int rc = conn.getResponseCode();
... // process it
}
catch( IOException e ){
// handle the error here
}
...
Kaynak
Yorumunuzu Ekleyin