HttpService.java
2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.bsth.serviec_jk.xl_basic;
import com.alibaba.fastjson.JSONObject;
import com.bsth.utils.HttpUtils;
import com.bsth.utils.postUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
public class HttpService {
private final static Logger log = LoggerFactory.getLogger(HttpUtils.class);
public static int httpRequestResult(JSONObject json, String token, String url, int count){
String result= null;
try {
result = postUtil.send(url, json, "UTF-8", token);
System.out.println(result);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
log.info("返回结果------------------"+result);
if(result !=null){
if(result.indexOf("state")!=-1){
log.info("第"+count+"次调用插入成功!");
return 1;
}else {
log.info("第"+count+"次调用插入失败!");
return -1;
}
}
log.info("第"+count+"次调用插入未返回数据!");
return -1;
}
public static int httpRequestResulty(String json, String token, String url, int count){
String result= null;
try {
result = postUtil.sendy(url, json, "UTF-8", token);
System.out.println(result);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
log.info("返回结果------------------"+result);
if(result !=null){
if(result.indexOf("state")!=-1){
log.info("第"+count+"次调用插入成功!");
return 1;
}else {
log.info("第"+count+"次调用插入失败!");
return -1;
}
}
log.info("第"+count+"次调用插入未返回数据!");
return -1;
}
}