0
点赞
收藏
分享

微信扫一扫

http请求代码

舟海君 2022-08-01 阅读 70

public void getRead(String productId,String userId,int mode, ImageView imageView){

//
String url = "http://host:port/projectname /init.jsp?type= productsubscribe &columntype=&productid="+productId+"&userid="+userId+"&mode="+mode+"";

// http://192.168.1.57:7001/SamBrandApps-FrontRecv1.4/

String url ="http://192.168.1.57:7001/SamBrandApps-FrontRecv1.4/init.jsp?type=columnsubscribe&columntype=&columnid=2&userid=22&mode="+mode;

try{


HttpGet httpGet = new HttpGet(url);

HttpResponse httpResponse = new DefaultHttpClient()

.execute(httpGet);

int respCode = httpResponse.getStatusLine().getStatusCode();




if (respCode == 200) {//=200成功

HttpEntity ent = httpResponse.getEntity(); //返回的

String result = EntityUtils.toString(ent);





SubScribeHandler scribeHandler = (SubScribeHandler)XmlSax.getHandlerObject(result, new SubScribeHandler()); //自己写的解析的类

String state = scribeHandler.getReturnValue();




if (Integer.valueOf(state) == 0) { //返回如果是0

//
imageView.setBackgroundResource(R.drawable.yidingyue);



}else {


}

}

}catch (ClientProtocolException e) {


e.printStackTrace();

} catch (IOException e) {


e.printStackTrace();

}

}

举报

相关推荐

0 条评论