求助,关于j2me的POST提交表单。急急急!!!十万火急!!!(源码已上,求版主帮忙解决。会的朋友也可以)
--------------------编程问答-------------------- 占楼发源码… --------------------编程问答-------------------- 继续占楼。 --------------------编程问答-------------------- →→→源码分隔线←←←/smile.java
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class smile extends MIDlet implements CommandListener,ItemCommandListener{
boolean bn;
int it;
Rms rs;
StringItem im;
ChoiceGroup cp;
Image se,iea,ieb,iec;
Image[] ie;
TextField tda,tdb,tdu,tdu,tdp;
Display dy;
List lt;
Command cdb,cde,cdm,tdad,tdbd,cdf;
Form fma,fmb;
Alert ata,atb,atc,atd,ate,atf;
Ticker tr;
public smile(){
bn=true;
rs=new Rms();
try{
Image start=Image.createImage("/start.png");
Image about=Image.createImage("/about.png");
Image more=Image.createImage("/more.png");
Image help=Image.createImage("/help.png");
Image exit=Image.createImage("/exit.png");
ie=new Image[]{start,help,more,about,exit};
}catch(java.io.IOException e){
}
String[] sga={"开始","帮助","更多","关于","退出"};
lt=new List("菜单",List.IMPLICIT,sga,ie);
cdf=new Command("发帖",Command.ITEM,2);
cde=new Command("退出",Command.EXIT,1);
cdb=new Command("返回",Command.BACK,1);
tdad=new Command("清除标题",Command.ITEM,0);
tdbd=new Command("清除内容",Command.ITEM,0);
im=new StringItem(null,"发帖",StringItem.BUTTON);
im.setDefaultCommand(cdf);
im.setItemCommandListener(this);
lt.addCommand(cde);
lt.setCommandListener(this);
if(bn){
fma=new Form("dospy发帖助手V1.0");
tr=new Ticker("★欢迎使用!★");
tda=new TextField("标题(1~160字符):",null,80,TextField.ANY);
tdb=new TextField("内容(1~5000字符):",null,5000,TextField.ANY);
String[] sgb={"求助","技术","软件","游戏","图铃","其他","固件","讨论","主题"};
cp=new ChoiceGroup("发帖类型:",ChoiceGroup.POPUP,sgb,null);
tdu=new TextField("账号:",rs.a,8,TextField.ANY);
tdp=new TextField("密码:",rs.b,5000,TextField.URL);
fma.setTicker(tr);
fma.append(cp);
fma.append(tda);
fma.append(tdb);
fma.append(tdu);
fma.append(tdp);
fma.append(im);
fma.addCommand(cde);
fma.addCommand(cdb);
fma.addCommand(tdad);
fma.addCommand(tdbd);
fma.setCommandListener(this);
bn=false;
}
fmb=new Form("帮助");
fmb.append("如果您没有账号,请到塞班论坛:\nhttp://bbs.dospy.com\n注册账号,然后再使用该软件,软件使用中若有问题,欢迎联系我.");
fmb.addCommand(cdb);
fmb.setCommandListener(this);
try{
se=Image.createImage("/se.png");
}catch(Exception e){
}
ata=new Alert("dospy发帖助手1.0","本软件由塞班s40区 hehe微笑 制作.\nQQ:1156518407",se,AlertType.INFO);
}
public void startApp(){
rs.restoreOptions();
dy=Display.getDisplay(this);
dy.setCurrent(lt);
}
public void pauseApp(){}
public void destroyApp(boolean unconditional){
if(rs.bn)
rs.bn=false;
rs.saveOptions();
rs.a=tdu.getString();
rs.b=tdp.getString();
fma.deleteAll();
notifyDestroyed();
}
public void send(){
try{
platformRequest("http://bbs.dospy.com/forum-15-1.html");
}catch(Exception e){
}
}
public void commandAction(Command c,Displayable d){
if(c==cdf){
fs();
}
if(c==cdb){
dy.setCurrent(lt);
}
if(c==cde){
destroyApp(true);
}
if(c==tdad){
try{
iea=Image.createImage("/iea.png");
}catch(Exception e){
}
try{
tda.delete(0,tda.getString().length());
atb= new Alert("提示","标题已清空",iea,AlertType.WARNING);
atb.setTimeout(1500);
dy.setCurrent(atb);
}catch(Exception e){
}
}
if(c==tdbd){
try{
tdb.delete(0,tdb.getString().length());
atc=new Alert("提示","内容已清空!",iea,AlertType.WARNING);
atc.setTimeout(1500);
dy.setCurrent(atc);
}catch(Exception e){
}
}
if(d.equals(lt)){
if(c==List.SELECT_COMMAND){
if(d.equals(lt)){
switch(((List)d).getSelectedIndex()){
case 0:
dy.setCurrent(fma);
break;
case 1:
dy.setCurrent(fmb);
break;
case 2:
send();
break;
case 3:
dy.setCurrent(ata);
break;
case 4:
destroyApp(true);
break;
}
}
}
}
}
public void commandAction(Command c,Itemi){
if(c==cdf){
fs();
}
}
public void getCookie(){
String session=null;
String cookie=hn.getHeaderField("Set-Cookie");
if(cookie!=null){
int n=cookie.indexOf(';');
session=cookie.substring(0,n);
}
if(session!=null)
hc.setRequestProperty("Cookie", session);
}
public void Dospy(){
try{
String url="http://bbs.dospy.com/wap/index.php?action=login&sid=tBUYyT_action=add&"+"username="+tdu.getString()+"&"+"password="+tdp.getString();
HttpConnection hn=(HttpConnection)Connector.open(url);
hn.setRequestMethod(HttpConnection.POST);
hn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
hn.setRequestProperty("Content-Length",Integer.toString(url.length()));
hn.setRequestProperty("User-Agent",System.getProperty("microedition.platform"));
OutputStream dmc=hn.openOutputStream();
dmc.write(url.getBytes("UTF-8"));
InputStream im=hn.openInputStream();
byte[] be=new byte[im.available()];
im.read(be);
String sg=new String(be,"UTF-8");
if(sg.indexOf("成功!")!=-1){
startApp();
ate=new Alert(null,"发帖成功!",null,AlertType.INFO);
}else{
startApp();
atf=new Alert(null,"发帖失败!",null,AlertType.INFO);
}
dmc.flush();
im.close();
dmc.close();
hn.close();
im=null;
dmc=null;
hn=null;
}catch(IOException e){
}
}
public void fs(){
it=cp.getSelectedIndex();
if(tda.size()==0||tdb.size()==0||tdu.size()==0||tdp.size()==0){
try{
ieb=Image.createImage("/ieb.png");
}catch(Exception e){
}
atd=new Alert("提示","请正确填写全部文本.",ieb,AlertType.WARNING);
atc.setTimeout(1500);dy.setCurrent(atd);
}else{
getCookie();
Dospy();
}
}
}
补充:Java , J2ME