If the URL contains a text file, it shows fine on the SDKs and on the real phone. If the link is a html, the phone will show the source code for it.
The object is such: my server script (btw. it's a 3rd party server) produces one line of text. Since the page extension is .php I guess the phone is trying to read something else. It IS nonetheless plain text.
Your phone only knows it is receiving a stream of bytes. If you use an HttpConnection the phone will parse the headers for you, but the body as far as it's concerned is just a plain stream of bytes. It has no concept of MIME types or extensions or anything else. Anything like that you would have to implement yourself. What matters is how your code interprets those bytes.
In the example you give this is the part that reads the stream and saves it as text:
Code:
while ((ch = is.read()) != -1) {
b.append((char) ch);
System.out.println((char)ch);
}
As you can see, it is reading in a byte, converting it to a char and appending it to a StringBuffer (this will only work for standard ASCII chars). Then it uses the StringBuffer to get a String from it.
Try printing out the actual bytes instead of adding them as chars of a string. Maybe it will help you make some sense of it.
As I said before, I think your server is encoding the text in a non-ASCII manner and that's why you get garbage. Another possibility is that WAP gateway you go through is doing some nasty stuff with the response. That could also explain why it works well on the emulator (the emulator is not going through the WAP gateway). A good way to test if the WAP gateway is the culprit would be to try and use the phone's browser to access that page and see if the result is any different.
Good luck,
shmoove