For JAVA scripters only! UNTRUSTED/1.0
#1

Hi all, I have a problem with HttpConnection. Here is the code:

Код:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;

public class Midlet extends MIDlet implements CommandListener {
    
    StringItem si = new StringItem("","");
    Form f = new Form("Internetas",new Item[] { si });
    Command exit = new Command("Iљeiti",Command.EXIT,0);
    Command ok = new Command("OK",Command.OK,0);
    
    public void commandAction(Command c, Displayable d) {
        if(c == exit) {
            notifyDestroyed();
        }
        if(c == ok) {
            HttpConnection conn = null;
            InputStream is = null;
            try {
                conn = (HttpConnection) Connector.open("http://localhost/a/");
                conn.setRequestMethod(HttpConnection.GET);
                conn.setRequestProperty("User-Agent","Profile/MIDP-2.1 Configuration/CLDC-1.1");
                int rc = conn.getResponseCode();
                String str;
                if(rc != HttpConnection.HTTP_OK) {
                    str = new String(rc + " " + conn.getResponseMessage());
                }
                else {
                    is = conn.openInputStream();
                    int len = (int) conn.getLength();
                    if(len != -1) {
                        byte id[] = new byte[len];
                        is.read(id);
                        str = new String(id);
                    }
                    else {
                        ByteArrayOutputStream bs = new ByteArrayOutputStream();
                        int ch;
                        while((ch = is.read()) != -1) {
                            bs.write(ch);
                        }
                        str = new String(bs.toByteArray());
                        bs.close();
                    }
                }
                si.setText(str);
            }
            catch(IOException e) {
                throw new IllegalArgumentException(e.getMessage());
            }
            finally {
                if(is != null) {
                    try {
                        is.close();
                    }
                    catch(Exception e) {
                        throw new IllegalArgumentException(e.getMessage());
                    }
                }
                if(conn != null) {
                    try {
                        conn.close();
                    }
                    catch(Exception e) {
                        throw new IllegalArgumentException(e.getMessage());
                    }
                }
            }
        }
    }

    public void startApp() {
        f.addCommand(exit);
        f.addCommand(ok);
        f.setCommandListener(this);
        Display.getDisplay(this).setCurrent(f);
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
}
And it's request headers are:

Код:
User-Agent: Profile/MIDP-2.1 Configuration/CLDC-1.1 UNTRUSTED/1.0
x-network-type: null
Content-Length: 0
Host: localhost
Accept: */*
The problem is that I can't set own request headers, it sends User-Agent as Profile/MIDP-2.1 Configuration/CLDC-1.1 UNTRUSTED/1.0, instead of Profile/MIDP-2.1 Configuration/CLDC-1.1.
Reply


Messages In This Thread
For JAVA scripters only! UNTRUSTED/1.0 - by sabretur - 13.06.2012, 15:30
Re: For JAVA scripters only! UNTRUSTED/1.0 - by Krx17 - 13.06.2012, 19:30
Re: For JAVA scripters only! UNTRUSTED/1.0 - by Mauzen - 13.06.2012, 19:47
Re: For JAVA scripters only! UNTRUSTED/1.0 - by sabretur - 13.06.2012, 20:02
Re: For JAVA scripters only! UNTRUSTED/1.0 - by sabretur - 13.06.2012, 20:06
Re: For JAVA scripters only! UNTRUSTED/1.0 - by Krx17 - 13.06.2012, 20:34
Re: For JAVA scripters only! UNTRUSTED/1.0 - by sabretur - 16.06.2012, 16:34
Re: For JAVA scripters only! UNTRUSTED/1.0 - by kikito - 16.06.2012, 16:38
Re: For JAVA scripters only! UNTRUSTED/1.0 - by sabretur - 16.06.2012, 20:08

Forum Jump:


Users browsing this thread: 5 Guest(s)