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
#2

It just means that the phone considers your connection untrusted. It should still work.

And why are you still programming for old Nokia's?
Reply
#3

As just said, Java ME for mobile phones uses a certification system for internet connections to see if applications are trusted or not, and then decides (depending on the phones setting) if it may access the internet or not. Getting an application trusted is an ugly thing afaik.

Why programming for old phones? Well I guess he got one and wants to create something for himself. 90% of what I program and script is just for myself because i want to experiment with it or just find it handy for a specific job
Reply
#4

Quote:
Originally Posted by Krx17
Посмотреть сообщение
It just means that the phone considers your connection untrusted. It should still work.

And why are you still programming for old Nokia's?
How can I script for new Nokia's? I'm a newbie in JAVA, I don't understand many things in this programming language.
Reply
#5

And why the client sends these unnecessary headers, like: x-network-type, Content-Length, etc?
Reply
#6

New Nokias are starting to use Windows Phone 7 as their OS, so to script for new Nokias, you need to script for Windows Phone 7. If you want to stick with Java, you can always go with Android.

It's really hard to find answers for your problem, since this problem is strictly related to Java ME/Nokia.
Reply
#7

I have one more question. Which connection should I use for connection to SA-MP servers for information (players online, hostname, gamemode, etc)? Socket Connection or Stream Connection? Maybe another?
Reply
#8

socket, since sa-mp use's udp.
Reply
#9

Quote:
Originally Posted by kikito
Посмотреть сообщение
socket, since sa-mp use's udp.
I tryed to connect to SA-MP server, but I get error 10061. What should I do?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)