第一种
public static String sendPost(String param) {
try {
WebClient client = WebClient.create(host);
client.reset();
client.header("Content-Type", "application/json; charset=UTF-8");
client.header("Authorization", "APPCODE " + appcode);
client.path(path);
Response r = client.post(param);
return r.readEntity(String.class);
} catch (Exception e) {
return null;
}
}
第二种
public static UnionPayService getUnionPayService() {
try {
UnionPayService unionPayService = JAXRSClientFactory.create(Config.UNURL, UnionPayService.class);
Client client = WebClient.client(unionPayService).header("Content-Type", "application/json");
HTTPConduit conduit = WebClient.getConfig(client).getHttpConduit();
conduit.getClient().setConnectionTimeout(5000); // 连接超时
conduit.getClient().setReceiveTimeout(5000); // 响应超时
return unionPayService;
} catch (Exception e) {
return JAXRSClientFactory.create(Config.UNURL, UnionPayService.class);
}
}
第三种
public static str sendAutoStatus(String cmbUrl) {
String str = null;
try {
String sign = getAutoStatusSign(appid, appsecret, park_code, vpl_number);
CmbChinaService cmbChinaService = JAXRSClientFactory.create(cmbUrl, CmbChinaService.class);
Response response = cmbChinaService.autoPayStatus(appid, park_code, vpl_number, sign);
str = response.readEntity(String.class);
} catch (Exception e) {
return null;
}
return str;
}
第四种
public TenetParkService setHeaderTenetParkServiceHttp() {
WebClient localClient = WebClient.fromClient(WebClient.client(tenetParkServiceHttp));
localClient.header("Version", "2015-08-01");
localClient.header("AccessKeyId", "tenetparkservice");
localClient.header("commKey", systemUtil.getCOMMKEY());
localClient.header("punitId", systemUtil.getPUNITID());
return JAXRSClientFactory.fromClient(localClient, TenetParkService.class, true);
}
本文介绍了四种在Java中调用Web服务的方法,包括使用WebClient进行POST请求、创建并配置UnionPayService服务、调用CmbChinaService的autoPayStatus方法以及设置TenetParkService的HTTP头部信息。每种方法都提供了详细的代码示例,帮助读者理解如何在实际项目中应用。
70

被折叠的 条评论
为什么被折叠?



