这个代理必须是10.0.0.172吗?还有如何使用这个代理连接一个网页,获取这个网页的文本代码?给出java代码最好谢谢!

解决方案 »

  1.   

    CMWAP的代理是10.0.0.172,端口可以是80或者9201.
      

  2.   

    HttpParams hparams = new BasicHttpParams();
    HttpClient client = new DefaultHttpClient(hparams);
    HttpHost proxy = new HttpHost("10.0.0.172", 80);      client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    HttpPost post = new HttpPost(url);
    HttpResponse hr = client.execute(post);
    if(hr.getStatusLine().getStatusCode()==HttpStatus.SC_OK){
    //取得返回结果
    InputStream is = hr.getEntity().getContent();
            }
      

  3.   

    楼上用的是apache的http库。如果用java.net将会是这样
    SocketAddress as = new InetSocketAddress("xxx.xx.xx.xxx" , 8080);
    Proxy proxy = new Proxy(Type.HTTP,as);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection(proxy);   
      

  4.   

    楼上2位都写的很对,
    能否写完整?就是 方法参数是 URL地址
    返回这个页面,如果RUL指向的是一个文件,比如XML,JPG,GIF,3GP,MP4,MP3之类的
    返回这个文件的BYTE[]另外也非常感谢 2位的回答!
      

  5.   

    public class MyResponse extends Response
    {
        private String resultCode;
        
        private String resultMsg;
        
        private ArrayList<MyResponseBean> list;
        
        public String getResultCode()
        {
            return resultCode;
        }
        
        public void setResultCode(String resultCode)
        {
            this.resultCode = resultCode;
        }
        
        public String getResultMsg()
        {
            return resultMsg;
        }
        
        public void setResultMsg(String resultMsg)
        {
            this.resultMsg = resultMsg;
        }
        
        public ArrayList<MyResponseBean> getList()
        {
            return list;
        }
        
        public void setList(ArrayList<MyResponseBean> list)
        {
            this.list = list;
        }
        
        public MyResponse(SoapObject so)
        {
            super(so);
        }
        
        protected void parseSoapObject()
        {
            SoapObject responseObj = (SoapObject)soapObj.getProperty(0);
            resultCode = responseObj.getProperty("resultCode").toString();
            resultMsg = responseObj.getProperty("resultMsg").toString();
            
            if (resultCode.equals("0"))
            {
                list = new ArrayList<MyResponseBean>();
                
                for (int i = 0; i < responseObj.getPropertyCount(); i++)
                {
                    if (responseObj.getProperty(i) instanceof SoapObject)
                    {
                        SoapObject soapObject = (SoapObject)responseObj.getProperty(i);
                        PropertyInfo info = new PropertyInfo();
                        responseObj.getPropertyInfo(i, info);
                        paseListBean(soapObject, info);
                    }
                }
            }
        }
        
        private void paseListBean(SoapObject soapObject, PropertyInfo info)
        {
            if ("list".equals(info.getName().trim()))
            {
                MyResponseBean MyResponseBean = new MyResponseBean();
                MyResponseBean.setAreaCode(soapObject.getProperty("areaCode").toString());
                MyResponseBean.setCode(soapObject.getProperty("code").toString());
                list.add(MyResponseBean);
            }
        }
        
    }