http请求代码

舟海君

关注

阅读 70

2022-08-01

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)

0 0 举报