|
|
|
@ -33,52 +33,52 @@ public class HttpRequestUtil extends BaseBean{
|
|
|
|
|
* @throws ParseException
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
|
public String sendPost(String url, Map<String,String> headers,String encoding){
|
|
|
|
|
String body = "";
|
|
|
|
|
|
|
|
|
|
BaseBean bb = new BaseBean();
|
|
|
|
|
bb.writeLog("url ==" + url);
|
|
|
|
|
|
|
|
|
|
//创建httpclient对象
|
|
|
|
|
CloseableHttpClient client = HttpClients.createDefault();
|
|
|
|
|
//创建post方式请求对象
|
|
|
|
|
HttpPost httpPost = new HttpPost(url);
|
|
|
|
|
|
|
|
|
|
//设置参数到请求对象中
|
|
|
|
|
if (headers != null && headers.size() > 0) {
|
|
|
|
|
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
|
|
|
|
bb.writeLog("key:"+entry.getKey());
|
|
|
|
|
bb.writeLog("val:"+entry.getValue());
|
|
|
|
|
httpPost.addHeader(entry.getKey(),entry.getValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//设置header信息
|
|
|
|
|
//指定报文头【Content-type】、【User-Agent】
|
|
|
|
|
// httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
|
|
|
|
|
|
|
|
|
|
//执行请求操作,并拿到结果(同步阻塞)
|
|
|
|
|
CloseableHttpResponse response = null;
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
response = client.execute(httpPost);
|
|
|
|
|
bb.writeLog(response.getStatusLine().getStatusCode());
|
|
|
|
|
//获取结果实体
|
|
|
|
|
HttpEntity entity = response.getEntity();
|
|
|
|
|
if (entity != null) {
|
|
|
|
|
//按指定编码转换结果实体为String类型
|
|
|
|
|
body = EntityUtils.toString(entity, encoding);
|
|
|
|
|
}
|
|
|
|
|
EntityUtils.consume(entity);
|
|
|
|
|
//释放链接
|
|
|
|
|
response.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
bb.writeLog("e:"+e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return body;
|
|
|
|
|
}
|
|
|
|
|
// public String sendPost(String url, Map<String,String> headers,String encoding){
|
|
|
|
|
// String body = "";
|
|
|
|
|
//
|
|
|
|
|
// BaseBean bb = new BaseBean();
|
|
|
|
|
// bb.writeLog("url ==" + url);
|
|
|
|
|
//
|
|
|
|
|
// //创建httpclient对象
|
|
|
|
|
// CloseableHttpClient client = HttpClients.createDefault();
|
|
|
|
|
// //创建post方式请求对象
|
|
|
|
|
// HttpPost httpPost = new HttpPost(url);
|
|
|
|
|
//
|
|
|
|
|
// //设置参数到请求对象中
|
|
|
|
|
// if (headers != null && headers.size() > 0) {
|
|
|
|
|
// for (Map.Entry<String, String> entry : headers.entrySet()) {
|
|
|
|
|
// bb.writeLog("key:"+entry.getKey());
|
|
|
|
|
// bb.writeLog("val:"+entry.getValue());
|
|
|
|
|
// httpPost.addHeader(entry.getKey(),entry.getValue());
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// //设置header信息
|
|
|
|
|
// //指定报文头【Content-type】、【User-Agent】
|
|
|
|
|
//// httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
|
|
|
|
|
//
|
|
|
|
|
// //执行请求操作,并拿到结果(同步阻塞)
|
|
|
|
|
// CloseableHttpResponse response = null;
|
|
|
|
|
// try {
|
|
|
|
|
//
|
|
|
|
|
// response = client.execute(httpPost);
|
|
|
|
|
// bb.writeLog(response.getStatusLine().getStatusCode());
|
|
|
|
|
// //获取结果实体
|
|
|
|
|
// HttpEntity entity = response.getEntity();
|
|
|
|
|
// if (entity != null) {
|
|
|
|
|
// //按指定编码转换结果实体为String类型
|
|
|
|
|
// body = EntityUtils.toString(entity, encoding);
|
|
|
|
|
// }
|
|
|
|
|
// EntityUtils.consume(entity);
|
|
|
|
|
// //释放链接
|
|
|
|
|
// response.close();
|
|
|
|
|
// } catch (IOException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// bb.writeLog("e:"+e);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// return body;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -89,69 +89,69 @@ public class HttpRequestUtil extends BaseBean{
|
|
|
|
|
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
|
|
|
|
* @return result 所代表远程资源的响应结果
|
|
|
|
|
*/
|
|
|
|
|
public String sendGet(String url, Map<String,String> headers,String uid) {
|
|
|
|
|
String result = "";
|
|
|
|
|
BufferedReader in = null;
|
|
|
|
|
|
|
|
|
|
BaseBean bb = new BaseBean();
|
|
|
|
|
bb.writeLog("url ==" + url);
|
|
|
|
|
bb.writeLog("uid ==" + uid);
|
|
|
|
|
try {
|
|
|
|
|
String urlNameString = url ;
|
|
|
|
|
URL realUrl = new URL(urlNameString); // 打开和URL之间的连接
|
|
|
|
|
HttpURLConnection connection= (HttpURLConnection) realUrl.openConnection();
|
|
|
|
|
connection.setRequestProperty("accept", "*/*");
|
|
|
|
|
connection.setRequestProperty("connection", "Keep-Alive");
|
|
|
|
|
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
|
|
|
|
|
|
|
|
|
connection.setDoOutput(true);
|
|
|
|
|
connection.setDoInput(true);
|
|
|
|
|
connection.setUseCaches(false);
|
|
|
|
|
connection.setRequestMethod("GET");
|
|
|
|
|
|
|
|
|
|
//connection.addRequestProperty("Cookie", "SESSION="+uid);
|
|
|
|
|
|
|
|
|
|
if (headers != null && headers.size() > 0)
|
|
|
|
|
{
|
|
|
|
|
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
|
|
|
|
bb.writeLog("key:"+entry.getKey());
|
|
|
|
|
bb.writeLog("val:"+entry.getValue());
|
|
|
|
|
connection.addRequestProperty(entry.getKey(), entry.getValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 建立实际的连接
|
|
|
|
|
connection.connect();
|
|
|
|
|
// 获取所有响应头字段
|
|
|
|
|
//Map<String, List<String>> map = connection.getHeaderFields();
|
|
|
|
|
// 遍历所有的响应头字段
|
|
|
|
|
//for (String key : map.keySet()) {
|
|
|
|
|
// System.out.println(key + "--->" + map.get(key));
|
|
|
|
|
//}
|
|
|
|
|
// 定义 BufferedReader输入流来读取URL的响应
|
|
|
|
|
in = new BufferedReader(new InputStreamReader(
|
|
|
|
|
connection.getInputStream(),"UTF-8"));
|
|
|
|
|
String line;
|
|
|
|
|
while ((line = in.readLine()) != null) {
|
|
|
|
|
result += line;
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
bb.writeLog("发送GET请求出现异常!" + e);
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
// 使用finally块来关闭输入流
|
|
|
|
|
finally {
|
|
|
|
|
try {
|
|
|
|
|
if (in != null) {
|
|
|
|
|
in.close();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e2) {
|
|
|
|
|
e2.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
// public String sendGet(String url, Map<String,String> headers,String uid) {
|
|
|
|
|
// String result = "";
|
|
|
|
|
// BufferedReader in = null;
|
|
|
|
|
//
|
|
|
|
|
// BaseBean bb = new BaseBean();
|
|
|
|
|
// bb.writeLog("url ==" + url);
|
|
|
|
|
// bb.writeLog("uid ==" + uid);
|
|
|
|
|
// try {
|
|
|
|
|
// String urlNameString = url ;
|
|
|
|
|
// URL realUrl = new URL(urlNameString); // 打开和URL之间的连接
|
|
|
|
|
// HttpURLConnection connection= (HttpURLConnection) realUrl.openConnection();
|
|
|
|
|
// connection.setRequestProperty("accept", "*/*");
|
|
|
|
|
// connection.setRequestProperty("connection", "Keep-Alive");
|
|
|
|
|
// connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
|
|
|
|
//
|
|
|
|
|
// connection.setDoOutput(true);
|
|
|
|
|
// connection.setDoInput(true);
|
|
|
|
|
// connection.setUseCaches(false);
|
|
|
|
|
// connection.setRequestMethod("GET");
|
|
|
|
|
//
|
|
|
|
|
// //connection.addRequestProperty("Cookie", "SESSION="+uid);
|
|
|
|
|
//
|
|
|
|
|
// if (headers != null && headers.size() > 0)
|
|
|
|
|
// {
|
|
|
|
|
// for (Map.Entry<String, String> entry : headers.entrySet()) {
|
|
|
|
|
// bb.writeLog("key:"+entry.getKey());
|
|
|
|
|
// bb.writeLog("val:"+entry.getValue());
|
|
|
|
|
// connection.addRequestProperty(entry.getKey(), entry.getValue());
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// // 建立实际的连接
|
|
|
|
|
// connection.connect();
|
|
|
|
|
// // 获取所有响应头字段
|
|
|
|
|
// //Map<String, List<String>> map = connection.getHeaderFields();
|
|
|
|
|
// // 遍历所有的响应头字段
|
|
|
|
|
// //for (String key : map.keySet()) {
|
|
|
|
|
// // System.out.println(key + "--->" + map.get(key));
|
|
|
|
|
// //}
|
|
|
|
|
// // 定义 BufferedReader输入流来读取URL的响应
|
|
|
|
|
// in = new BufferedReader(new InputStreamReader(
|
|
|
|
|
// connection.getInputStream(),"UTF-8"));
|
|
|
|
|
// String line;
|
|
|
|
|
// while ((line = in.readLine()) != null) {
|
|
|
|
|
// result += line;
|
|
|
|
|
// }
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// bb.writeLog("发送GET请求出现异常!" + e);
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
// // 使用finally块来关闭输入流
|
|
|
|
|
// finally {
|
|
|
|
|
// try {
|
|
|
|
|
// if (in != null) {
|
|
|
|
|
// in.close();
|
|
|
|
|
// }
|
|
|
|
|
// } catch (Exception e2) {
|
|
|
|
|
// e2.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// return result;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
@ -164,7 +164,7 @@ public class HttpRequestUtil extends BaseBean{
|
|
|
|
|
public String httpGet1(String url, Map<String,String> headers, String encode){
|
|
|
|
|
|
|
|
|
|
BaseBean bb = new BaseBean();
|
|
|
|
|
bb.writeLog("url",url);
|
|
|
|
|
//bb.writeLog("url",url);
|
|
|
|
|
if(encode == null){
|
|
|
|
|
encode = "UTF-8";
|
|
|
|
|
}
|
|
|
|
@ -187,7 +187,7 @@ public class HttpRequestUtil extends BaseBean{
|
|
|
|
|
httpResponse = closeableHttpClient.execute(httpGet);
|
|
|
|
|
|
|
|
|
|
if(httpResponse.getStatusLine().getStatusCode() == 200){
|
|
|
|
|
bb.writeLog(httpResponse.getStatusLine().getStatusCode());
|
|
|
|
|
//bb.writeLog(httpResponse.getStatusLine().getStatusCode());
|
|
|
|
|
HttpEntity entity = httpResponse.getEntity();
|
|
|
|
|
content = EntityUtils.toString(entity, encode);
|
|
|
|
|
}
|
|
|
|
@ -217,58 +217,58 @@ public class HttpRequestUtil extends BaseBean{
|
|
|
|
|
* @param encode
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public String httpGet2(String url,Map<String,String> headers,String encode)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
BaseBean bb = new BaseBean();
|
|
|
|
|
bb.writeLog("url",url);
|
|
|
|
|
if(encode == null){
|
|
|
|
|
encode = "UTF-8";
|
|
|
|
|
}
|
|
|
|
|
CloseableHttpResponse httpResponse = null;
|
|
|
|
|
CloseableHttpClient closeableHttpClient = null;
|
|
|
|
|
String content = null;
|
|
|
|
|
//since 4.3 不再使用 DefaultHttpClient
|
|
|
|
|
try {
|
|
|
|
|
closeableHttpClient = HttpClientBuilder.create().build();
|
|
|
|
|
HttpGet httpGet = new HttpGet(url);
|
|
|
|
|
//设置header
|
|
|
|
|
if (headers != null && headers.size() > 0) {
|
|
|
|
|
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
|
|
|
|
|
|
|
|
|
bb.writeLog("key:"+entry.getKey());
|
|
|
|
|
bb.writeLog("val:"+entry.getValue());
|
|
|
|
|
|
|
|
|
|
httpGet.addHeader(entry.getKey(),entry.getValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
httpGet.setHeader("Accept", "*");
|
|
|
|
|
|
|
|
|
|
httpResponse = closeableHttpClient.execute(httpGet);
|
|
|
|
|
if(httpResponse.getStatusLine().getStatusCode() == 200)
|
|
|
|
|
{
|
|
|
|
|
bb.writeLog(httpResponse.getStatusLine().getStatusCode());
|
|
|
|
|
HttpEntity entity = httpResponse.getEntity();
|
|
|
|
|
content = EntityUtils.toString(entity, encode);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
bb.writeLog("er333:"+e);
|
|
|
|
|
}finally{
|
|
|
|
|
try {
|
|
|
|
|
httpResponse.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
try { //关闭连接、释放资源
|
|
|
|
|
closeableHttpClient.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return content;
|
|
|
|
|
}
|
|
|
|
|
// public String httpGet2(String url,Map<String,String> headers,String encode)
|
|
|
|
|
// {
|
|
|
|
|
//
|
|
|
|
|
// BaseBean bb = new BaseBean();
|
|
|
|
|
// bb.writeLog("url",url);
|
|
|
|
|
// if(encode == null){
|
|
|
|
|
// encode = "UTF-8";
|
|
|
|
|
// }
|
|
|
|
|
// CloseableHttpResponse httpResponse = null;
|
|
|
|
|
// CloseableHttpClient closeableHttpClient = null;
|
|
|
|
|
// String content = null;
|
|
|
|
|
// //since 4.3 不再使用 DefaultHttpClient
|
|
|
|
|
// try {
|
|
|
|
|
// closeableHttpClient = HttpClientBuilder.create().build();
|
|
|
|
|
// HttpGet httpGet = new HttpGet(url);
|
|
|
|
|
// //设置header
|
|
|
|
|
// if (headers != null && headers.size() > 0) {
|
|
|
|
|
// for (Map.Entry<String, String> entry : headers.entrySet()) {
|
|
|
|
|
//
|
|
|
|
|
// bb.writeLog("key:"+entry.getKey());
|
|
|
|
|
// bb.writeLog("val:"+entry.getValue());
|
|
|
|
|
//
|
|
|
|
|
// httpGet.addHeader(entry.getKey(),entry.getValue());
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// httpGet.setHeader("Accept", "*");
|
|
|
|
|
//
|
|
|
|
|
// httpResponse = closeableHttpClient.execute(httpGet);
|
|
|
|
|
// if(httpResponse.getStatusLine().getStatusCode() == 200)
|
|
|
|
|
// {
|
|
|
|
|
// bb.writeLog(httpResponse.getStatusLine().getStatusCode());
|
|
|
|
|
// HttpEntity entity = httpResponse.getEntity();
|
|
|
|
|
// content = EntityUtils.toString(entity, encode);
|
|
|
|
|
// }
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// bb.writeLog("er333:"+e);
|
|
|
|
|
// }finally{
|
|
|
|
|
// try {
|
|
|
|
|
// httpResponse.close();
|
|
|
|
|
// } catch (IOException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// try { //关闭连接、释放资源
|
|
|
|
|
// closeableHttpClient.close();
|
|
|
|
|
// } catch (IOException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
// return content;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*
|
|
|
|
@ -276,37 +276,37 @@ public class HttpRequestUtil extends BaseBean{
|
|
|
|
|
* @param jsonstr
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String doPostByAuth(String url,String jsonstr,String auth){
|
|
|
|
|
CloseableHttpClient httpClient = null;
|
|
|
|
|
HttpPost httpPost = null;
|
|
|
|
|
String result = null;
|
|
|
|
|
try{
|
|
|
|
|
String authStr = new String(Base64.encode(auth));
|
|
|
|
|
httpClient = HttpClients.createDefault();
|
|
|
|
|
httpPost = new HttpPost(url);
|
|
|
|
|
// String head_param_encode = urlEncode(head_param);
|
|
|
|
|
System.out.println("authStr:"+authStr);
|
|
|
|
|
httpPost.addHeader("Connection", "Keep-Alive");
|
|
|
|
|
httpPost.addHeader("Cache-Control", "No-Cache");
|
|
|
|
|
httpPost.addHeader("Accept", "*/*");
|
|
|
|
|
httpPost.addHeader("Content-Type", "application/json;charset=utf-8");
|
|
|
|
|
httpPost.addHeader("Authorization", "Basic " + authStr);
|
|
|
|
|
httpPost.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36");
|
|
|
|
|
StringEntity se = new StringEntity(jsonstr);
|
|
|
|
|
se.setContentType("application/json;charset=utf-8");
|
|
|
|
|
httpPost.setEntity(se);
|
|
|
|
|
HttpResponse response = httpClient.execute(httpPost);
|
|
|
|
|
if(response != null){
|
|
|
|
|
HttpEntity resEntity = response.getEntity();
|
|
|
|
|
if(resEntity != null){
|
|
|
|
|
result = EntityUtils.toString(resEntity,"utf-8");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}catch(Exception ex){
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
// public static String doPostByAuth(String url,String jsonstr,String auth){
|
|
|
|
|
// CloseableHttpClient httpClient = null;
|
|
|
|
|
// HttpPost httpPost = null;
|
|
|
|
|
// String result = null;
|
|
|
|
|
// try{
|
|
|
|
|
// String authStr = new String(Base64.encode(auth));
|
|
|
|
|
// httpClient = HttpClients.createDefault();
|
|
|
|
|
// httpPost = new HttpPost(url);
|
|
|
|
|
//// String head_param_encode = urlEncode(head_param);
|
|
|
|
|
// System.out.println("authStr:"+authStr);
|
|
|
|
|
// httpPost.addHeader("Connection", "Keep-Alive");
|
|
|
|
|
// httpPost.addHeader("Cache-Control", "No-Cache");
|
|
|
|
|
// httpPost.addHeader("Accept", "*/*");
|
|
|
|
|
// httpPost.addHeader("Content-Type", "application/json;charset=utf-8");
|
|
|
|
|
// httpPost.addHeader("Authorization", "Basic " + authStr);
|
|
|
|
|
// httpPost.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36");
|
|
|
|
|
// StringEntity se = new StringEntity(jsonstr);
|
|
|
|
|
// se.setContentType("application/json;charset=utf-8");
|
|
|
|
|
// httpPost.setEntity(se);
|
|
|
|
|
// HttpResponse response = httpClient.execute(httpPost);
|
|
|
|
|
// if(response != null){
|
|
|
|
|
// HttpEntity resEntity = response.getEntity();
|
|
|
|
|
// if(resEntity != null){
|
|
|
|
|
// result = EntityUtils.toString(resEntity,"utf-8");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }catch(Exception ex){
|
|
|
|
|
// ex.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
// return result;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public static String urlEncode(String url) throws UnsupportedEncodingException {
|
|
|
|
@ -327,29 +327,29 @@ public class HttpRequestUtil extends BaseBean{
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String doPostByAuth2(String dataJson){
|
|
|
|
|
BaseBean bb = new BaseBean();
|
|
|
|
|
String msgData = "" ;
|
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
|
.build();
|
|
|
|
|
MediaType mediaType = MediaType.parse("application/json");
|
|
|
|
|
RequestBody body = RequestBody.create(mediaType, dataJson);
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
|
.url("http://172.16.25.133/portal-web/centerTodo/sync")
|
|
|
|
|
.method("POST", body)
|
|
|
|
|
.addHeader("Authorization", "Basic YWRtaW46VXBvcnRhbF8xMjM=")
|
|
|
|
|
.addHeader("Content-Type", "application/json")
|
|
|
|
|
.build();
|
|
|
|
|
try {
|
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
|
bb.writeLog("response.code():"+response.code());
|
|
|
|
|
bb.writeLog("response.body():"+response.body().string());
|
|
|
|
|
|
|
|
|
|
msgData = response.body().string();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return msgData;
|
|
|
|
|
}
|
|
|
|
|
// public String doPostByAuth2(String dataJson){
|
|
|
|
|
// BaseBean bb = new BaseBean();
|
|
|
|
|
// String msgData = "" ;
|
|
|
|
|
// OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
|
// .build();
|
|
|
|
|
// MediaType mediaType = MediaType.parse("application/json");
|
|
|
|
|
// RequestBody body = RequestBody.create(mediaType, dataJson);
|
|
|
|
|
// Request request = new Request.Builder()
|
|
|
|
|
// .url("http://172.16.25.133/portal-web/centerTodo/sync")
|
|
|
|
|
// .method("POST", body)
|
|
|
|
|
// .addHeader("Authorization", "Basic YWRtaW46VXBvcnRhbF8xMjM=")
|
|
|
|
|
// .addHeader("Content-Type", "application/json")
|
|
|
|
|
// .build();
|
|
|
|
|
// try {
|
|
|
|
|
// Response response = client.newCall(request).execute();
|
|
|
|
|
// bb.writeLog("response.code():"+response.code());
|
|
|
|
|
// bb.writeLog("response.body():"+response.body().string());
|
|
|
|
|
//
|
|
|
|
|
// msgData = response.body().string();
|
|
|
|
|
// } catch (IOException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
// return msgData;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|