2024年6月11日发(作者:)
HttpClient httpclient = new DefaultHttpClient();
String uri = "localhost:8080/springMVC/user/getUserByName";
HttpPost httppost = new HttpPost(uri);
//添加http头信息
der("Authorization", "your token"); //认证token
der("Content-Type", "application/json");
der("User-Agent", "imgfornote");
JSONObject obj = new JSONObject();
("name", "cwh");
ity(new StringEntity(ng()));
HttpResponse response;
response = e(httppost);
//检验状态码,如果成功接收数据
int code = tusLine().getStatusCode();
n(code+"code");
if (code == 200) {
String rev = ng(ity());//返回json格式: {"id": "","name": ""}
obj= ject(rev);
User user = (User)(obj,);
n("返回数据==="+ng());
}
} catch (ClientProtocolException e) {
tackTrace();
} catch (IOException e) {
tackTrace();
} catch (Exception e) {
tackTrace();
}
}
}


发布评论