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

📄 http.java

📁 j2me写的google地图
💻 JAVA
字号:
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov  Date: 2008-6-16 11:25:07
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   HTTP.java

package com.eightmotions.util;

import java.io.*;
import javax.microedition.io.HttpConnection;

// Referenced classes of package com.eightmotions.util:
//            URLFetcher

public class HTTP
{

    public HTTP()
    {
    }

    public static String sendPostRequest(String requeststring, String url, String boundary)
    {
        HttpConnection hc;
        DataInputStream dis;
        DataOutputStream dos;
        StringBuffer messagebuffer;
        hc = null;
        dis = null;
        dos = null;
    	try
    	{
        messagebuffer = new StringBuffer();
        System.out.println("Sending:" + url.toString());
        hc = URLFetcher.open(url);
        hc.setRequestMethod("POST");
        if(boundary != null)
            hc.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
        byte request_body[] = requeststring.getBytes();
        hc.setRequestProperty("Content-Length", Integer.toString(request_body.length));
        dos = hc.openDataOutputStream();
        for(int i = 0; i < request_body.length; i++)
        {
            dos.writeByte(request_body[i]);
            if(i % 100 == 0)
                System.out.println("writing..." + i);
        }

        System.out.println("Writing ok");
        messagebuffer.append(hc.getResponseMessage() + "\r\n");
        dis = new DataInputStream(hc.openInputStream());
        long len = hc.getLength();
        int ch;
        if(len != -1L)
        {
            for(int i = 0; (long)i < len; i++)
                if((ch = dis.read()) != -1)
                    messagebuffer.append((char)ch);

        } else
        {
            while((ch = dis.read()) != -1) 
                messagebuffer.append((char)ch);
        }
        dis.close();
        try
        {
            if(hc != null)
                hc.close();
        }
        catch(IOException ignored) { }
        try
        {
            if(dis != null)
                dis.close();
        }
        catch(IOException ignored) { }
        try
        {
            if(dos != null)
                dos.close();
        }
        catch(IOException ignored) { }
//        break MISSING_BLOCK_LABEL_483;
    	}catch(IOException ioe)
        {
         ioe.printStackTrace();
        }
    	messagebuffer = new StringBuffer("ERROR!");
        try
        {
            if(hc != null)
                hc.close();
        }
        catch(IOException ignored) { }
        try
        {
            if(dis != null)
                dis.close();
        }
        catch(IOException ignored) { }
        try
        {
            if(dos != null)
                dos.close();
        }
        catch(IOException ignored) { }
//        break MISSING_BLOCK_LABEL_483;
//        Exception exception;
//        exception;
        try
        {
            if(hc != null)
                hc.close();
        }
        catch(IOException ignored) { }
        try
        {
            if(dis != null)
                dis.close();
        }
        catch(IOException ignored) { }
        try
        {
            if(dos != null)
                dos.close();
        }
        catch(IOException ignored) { }
//        throw exception;
        return messagebuffer.toString();
    }

    public static String sendGetRequest(String url)
    {
    	try
    	{
        HttpConnection hc;
        DataInputStream dis;
        DataOutputStream dos;
        StringBuffer messagebuffer;
        hc = null;
        dis = null;
        dos = null;
        messagebuffer = new StringBuffer();
        System.out.println(url);
        hc = URLFetcher.open(url);
        hc.setRequestMethod("GET");
        messagebuffer.append(hc.getResponseMessage() + "\r\n");
        dis = new DataInputStream(hc.openInputStream());
        long len = hc.getLength();
        int ch;
        if(len != -1L)
        {
            for(int i = 0; (long)i < len; i++)
                if((ch = dis.read()) != -1)
                    messagebuffer.append((char)ch);

        } else
        {
            while((ch = dis.read()) != -1) 
                messagebuffer.append((char)ch);
        }
        dis.close();
        try
        {
            if(hc != null)
                hc.close();
        }
        catch(IOException ignored) { }
        try
        {
            if(dis != null)
                dis.close();
        }
        catch(IOException ignored) { }
        try
        {
            if(dos != null)
                dos.close();
        }
        catch(IOException ignored) { }
//        break MISSING_BLOCK_LABEL_311;
//        IOException ioe;
//        ioe;
        messagebuffer = new StringBuffer("ERROR!");
        try
        {
            if(hc != null)
                hc.close();
        }
        catch(IOException ignored) { }
        try
        {
            if(dis != null)
                dis.close();
        }
        catch(IOException ignored) { }
        try
        {
            if(dos != null)
                dos.close();
        }
        catch(IOException ignored) { }
//        break MISSING_BLOCK_LABEL_311;
//        Exception exception;
//        exception;
        try
        {
            if(hc != null)
                hc.close();
        }
        catch(IOException ignored) { }
        try
        {
            if(dis != null)
                dis.close();
        }
        catch(IOException ignored) { }
        try
        {
            if(dos != null)
                dos.close();
        }
        catch(IOException ignored) { }
//        throw exception;
//        System.out.println("Result of send:" + messagebuffer.toString());
        return messagebuffer.toString();
    	}catch(Exception e)
    	{
    		return null;
    	}
    }

}

⌨️ 快捷键说明

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