⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httplogin.java

📁 关于j2me的宠物游戏!!!!!!!!!!! 希望打架提出意见
💻 JAVA
字号:
/*
 * HttpLogin.java
 *
 * Created on 2006年5月12日, 下午9:26
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package DogPet;

import javax.microedition.lcdui.*; 
import javax.microedition.midlet.*; 
import javax.microedition.io.*; 
import java.io.*; 

public class HttpLogin implements Runnable{
    
   HttpConnection httpConn;
  public HttpLogin(String url)    //String url
  {
    try {
      postHttpConnection(url);
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }

  void postHttpConnection(String url) throws IOException {
    HttpConnection c = null;
    InputStream is = null;
    OutputStream os = null;

    try {
        c = (HttpConnection)Connector.open(url);
        c.setRequestMethod(HttpConnection.POST);
        c.setRequestProperty("If-Modified-Since",
            "16 Apr 2006 19:43:31 GMT");
        c.setRequestProperty("User-Agent",
            "Profile/MIDP-2.0 Configuration/CLDC-1.1");
        c.setRequestProperty("Content-Language", "en-US");

        // Getting the output stream may flush the headers
       /* os = c.openOutputStream();
        DataOutputStream dos = new DataOutputStream(os);
        os.write("HELLO,WORLD".getBytes());*/
        // 一些手机,在此加入flush可能导致http server不能获得请求信息。
        //os.flush();// nokia 需要加入

        is = c.openInputStream();

        String type = c.getType();
        System.out.println("type : " + type);
        DataInputStream dis = new DataInputStream(is);
        int length = dis.available();
        byte [] reponseBytes = new byte[length];
        dis.read(reponseBytes);
        System.out.println("Received . :" + new String(reponseBytes));

    } finally {
        if (is != null)
            is.close();
        if (os != null)
            os.close();
        if (c != null)
            c.close();
    }
}

    public void run()
    {
        //?????????????????????????????????????????????????????????????????
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -