扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:中国IT实验室 来源:中国IT实验室 2007年9月22日
关键字:
在本页阅读全文(共4页)
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.TextField;
public class InputCanvas extends Form implements CommandListener
{
private UIController uicontroller;
private TextField inputField;
private StringItem result;
public static final Command okCommand = new Command("OK", Command.OK, 1);
public InputCanvas(UIController uicontroller)
{
super("Http Comunication");
this.uicontroller = uicontroller;
inputField = new TextField("Input:", null, 20, TextField.ANY);
this.append(inputField);
this.addCommand(okCommand);
this.setCommandListener(this);
}
public void commandAction(Command arg0, Displayable arg1)
{
if (arg0 == okCommand)
{
String input = inputField.getString();
uicontroller.handleEvent(UIController.EventID.CONNECT_TO_SERVER,
new Object[] { input });
}
}
}
import java.io.*;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
public class HttpCommHandler
{
private String URL;
public HttpCommHandler(String URL)
{
this.URL = URL;
}
public String sendMessage(String message) throws IOException
{
HttpConnection httpConn;
DataInputStream input;
DataOutputStream output;
String result;
try
{
httpConn = open();
output = this.openDataOutputStream(httpConn);
output.writeUTF(message);
output.close();
input = this.openDataInputStream(httpConn);
result = input.readUTF();
closeConnection(httpConn,input,output);
return result;
}
finally
{
}
}
public HttpConnection open() throws IOException
{
try
{
HttpConnection connection = (HttpConnection) Connector.open(URL);
connection.setRequestProperty("User-Agent", System
.getProperty("microedition.profiles"));
connection.setRequestProperty("Content-Type",
"application/octet-stream");
connection.setRequestMethod(HttpConnection.POST);
return connection;
} catch (IOException ioe)
{
throw ioe;
}
}
private DataInputStream openDataInputStream(HttpConnection conn)
throws IOException
{
int code = conn.getResponseCode();
if (code == HttpConnection.HTTP_OK)
{
return conn.openDataInputStream();
} else
{
throw new IOException();
}
}
private DataOutputStream openDataOutputStream(HttpConnection conn)
throws IOException
{
return conn.openDataOutputStream();
}
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者