HTTP 通过url接口提取数据

commandAction调用方法:
if(c == download){
String url = "http://127.0.01/接口";
WorkThread wt = new WorkThread(url,uicontroler,this) ;
         wt.start() ;
}

传输方法:
package Util;

import javax.microedition.io.*;
import java.io.*;
public class WorkThread extends Thread
{
public Object aaa;
    String url ;
private UIControler uicontroler;
    public WorkThread(String url,UIControler uicontroler,Object object)
    {
    aaa = object;
        this.url = url ;
        this.uicontroler = uicontroler;
        System.out.println("准备连接:"+this.url) ;
    }
    public void run()
    {
        HttpConnection conn = null;
        InputStream is = null;
        InputStreamReader isr = null ;
        StringBuffer line = new StringBuffer("");
        try {
                conn = (HttpConnection)Connector.open(url);
            System.out.println("内容长度:" + conn.getLength()) ;
               is = conn.openInputStream();   
               isr = new InputStreamReader(is) ;
               int ic ;           
               while( (ic = isr.read()) != -1 )
            {
                line.append((char)ic) ;
            }           
         }catch (Exception ioe)
         {
//             System.out.println(ioe);
         }finally
         {
             try
             {
                 if(conn!=null)
                     conn.close();
             }catch(Exception e){}
         }
         String test;
         if(line.toString().substring(0, 1).equals("0")){
        test="您已下载过此优惠券";
         }else{
        test="已下发请查收";
         }
         uicontroler.displayErrorForTalk(test, aaa);
    }
}
打印方法:
public void displayErrorForTalk(String string, Object object) {
errorUI.setType(AlertType.ERROR);
errorUI.setString(string);
errorUI.setTimeout(1500);
midlet.setCurrent(errorUI, (Displayable) object);
}

你可能感兴趣的:(thread,C++,c,C#)