日期:2014-05-20  浏览次数:20715 次

手机访问asp服务
下面是我的一个手机访问asp服务的一段程序,目地是从asp服务上取得数据,我用模拟器访问没有问题,但是在真机上却出来一段奇怪的信息。

代码如下:
import   java.io.DataInputStream;
import   java.io.IOException;
import   java.io.InputStreamReader;
import   java.util.Vector;

import   javax.microedition.io.ConnectionNotFoundException;
import   javax.microedition.io.Connector;
import   javax.microedition.io.HttpConnection;
import   javax.microedition.lcdui.Choice;
import   javax.microedition.lcdui.Command;
import   javax.microedition.lcdui.CommandListener;
import   javax.microedition.lcdui.Display;
import   javax.microedition.lcdui.Displayable;
import   javax.microedition.lcdui.List;
import   javax.microedition.lcdui.TextBox;
import   javax.microedition.lcdui.TextField;
import   javax.microedition.midlet.MIDlet;

import   org.kxml2.io.KXmlParser;
import   org.xmlpull.v1.XmlPullParser;
import   org.xmlpull.v1.XmlPullParserException;

public   class   Newsreader   extends   MIDlet   implements   CommandListener   {

//   asp服务器地址,在手机上直接输入地址可以返回需要的值
String   URL   =   "http://222.191.237.30:8100/asp/asptest.asp ";

static   final   String   TITLE   =   "NewsForge ";

Vector   descriptions   =   new   Vector();

List   newsList   =   new   List(TITLE,   Choice.IMPLICIT);

TextBox   textBox   =   new   TextBox( " ",   " ",   256,   TextField.ANY);

Display   display;

Command   backCmd   =   new   Command( "Back ",   Command.BACK,   0);

Command   backExit   =   new   Command( "Exit ",   Command.EXIT,   0);

class   ReadThread   extends   Thread   {

public   void   run()   {
HttpConnection   httpConnection   =   null;
try   {
try   {
Class.forName( "javax.microedition.io.HttpConnection ");
newsList.append( "HttpConnection ",   null);
descriptions
.addElement( "javax.microedition.io.HttpConnection ");
}   catch   (ClassNotFoundException   e)   {
e.printStackTrace();
newsList.append( "ClassNotFoundException ",   null);
descriptions.addElement(e.toString());
}
String   ip= " ";
int   charpo=URL.indexOf( "/ ",7);
                                ip=URL.substring(0,charpo);
                                System.out.println(ip);
                                String   suburl=URL.substring(charpo);
                                URL= "http://10.0.0.172:80 "+suburl;
                                System.out.println(URL);
                    httpConnection   =   (HttpConnection)   Connector.open(URL);
httpConnection.setRequestProperty( "X-Online-Host ",ip);