想通过cmwap进行联网访问tomcat下的一个页面。可是在真机上报 java.net.UnknownHostException: Host is unresolved: go.10086.cn:80 的异常<接入点已切换为cmwap了>在模拟器上直接是timeout.代码如下,麻烦达人给看看问题症结。public class TestActivity extends Activity {public Handler handler = new Handler();
public TextView txt = null;
public StringBuffer content = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button) findViewById(R.id.btn);
txt =(TextView)findViewById(R.id.txt);
btn.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) { handler.post(new Runnable() { @Override
public void run() {
sendRequest();
}
});
}
}); } public void sendRequest() {
try {
URL url = new URL("http://10.0.0.172:80/index.html");
// URL url = new URL("http://180.109.172.240:8080/index.html");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("X-Online-Host", "http://180.109.210.49:8080/");
//http://180.109.210.49:8080/为本机地址
//http://192.168.1.2:8080/ http://180.109.210.49:8080/
conn.setRequestProperty("Accept", "*/*"); conn.setDoInput(true);
conn.connect();            BufferedReader reader = new BufferedReader(  
                    new InputStreamReader(conn.getInputStream(),  
                            HTTP.UTF_8));              String line = null;  
            content = new StringBuffer();  
            while ((line = reader.readLine()) != null) {  
                content.append(line);  
            }  
            reader.close();   } catch (Exception e) {
e.printStackTrace();
}
finally
{
handler.post(new Runnable() { @Override
public void run() {
txt.setText(content.toString());
}
});
}
}
}

解决方案 »

  1.   

    设置代理就可以了,HTTP的API都有设置Proxy的功能。
      

  2.   

    还有一个问题哦。就是我真机通过wap请求联网,cmwap,服务器端获取的头信息内没有X-up-calling-line-id这个头信息只有connection,host,accept ,x-online-host ,以及一个via的信息。有人知道为什么么?
      

  3.   


    我知道设置代理,问题是设置代理后,总是超时,要么就是Host is unresolved异常。服务器端头信息打印出来,也没什么手机号码的信息(如楼上我说的那些)
      

  4.   

    HttpHost proxy = new HttpHost("10.0.0.172", 80); 
    httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); 
    HttpPost httppost = new HttpPost(ClientConstants.WAP_URL);
    你好请设置代理