问问,如何使用HTTP的代理方式连接? 这个代理必须是10.0.0.172吗?还有如何使用这个代理连接一个网页,获取这个网页的文本代码?给出java代码最好谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CMWAP的代理是10.0.0.172,端口可以是80或者9201. 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(); } 楼上用的是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); 楼上2位都写的很对,能否写完整?就是 方法参数是 URL地址返回这个页面,如果RUL指向的是一个文件,比如XML,JPG,GIF,3GP,MP4,MP3之类的返回这个文件的BYTE[]另外也非常感谢 2位的回答! 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); } } } android入门——对话框(普通、列表带图标或普通列表、单选、多选) NEC平板开不了机,急求助 android3.1以上usbhost读取连接usb设备的数据 android的文件浏览器,怎样读取文件? 关于缓存图片到sd卡里的 好吧,我直接来求助如何通过蓝牙发送通讯录 android 添加CheckBox单击事件编译通过,但模拟器中报错,这是为什么? 40分求解:如何得到当前activity自身的状态 android framework求解 Android pull解析这种格式不一致的xml怎么做 tabhost问题 怎样用keytool生成MD5认证指纹?
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();
}
SocketAddress as = new InetSocketAddress("xxx.xx.xx.xxx" , 8080);
Proxy proxy = new Proxy(Type.HTTP,as);
HttpURLConnection conn = (HttpURLConnection) url.openConnection(proxy);
能否写完整?就是 方法参数是 URL地址
返回这个页面,如果RUL指向的是一个文件,比如XML,JPG,GIF,3GP,MP4,MP3之类的
返回这个文件的BYTE[]另外也非常感谢 2位的回答!
{
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);
}
}
}