You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.4 KiB
Java
54 lines
1.4 KiB
Java
2 years ago
|
package com.customization.dito.sendtodo;
|
||
3 years ago
|
|
||
|
import com.sun.jersey.core.util.Base64;
|
||
|
import okhttp3.*;
|
||
|
import weaver.general.BaseBean;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
|
||
|
public class HttpRequestUtil extends BaseBean{
|
||
|
|
||
|
/***
|
||
|
*
|
||
|
* @param dataJson
|
||
|
* @return
|
||
|
*/
|
||
|
public String doPostByAuth(String portal_todourl,String dataJson,String auth){
|
||
|
//"http://172.16.25.133/portal-web/centerTodo/sync"
|
||
|
BaseBean bb = new BaseBean();
|
||
|
|
||
|
String authorization = "Basic "+new String(Base64.encode(auth));
|
||
|
bb.writeLog("authorization:"+authorization);
|
||
|
bb.writeLog("portal_todourl:"+portal_todourl);
|
||
|
bb.writeLog("dataJson:"+dataJson);
|
||
|
bb.writeLog("auth:"+auth);
|
||
|
|
||
|
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(portal_todourl)
|
||
|
.method("POST", body)
|
||
|
.addHeader("Authorization", authorization)
|
||
|
.addHeader("Content-Type", "application/json")
|
||
|
.build();
|
||
|
try {
|
||
|
Response response = client.newCall(request).execute();
|
||
|
|
||
3 years ago
|
int code = response.code();
|
||
3 years ago
|
String bodyMsg = response.body().string();
|
||
3 years ago
|
bb.writeLog("response.code():"+code);
|
||
|
bb.writeLog("response.body():"+bodyMsg);
|
||
|
if(code == 200){
|
||
|
msgData = bodyMsg;
|
||
3 years ago
|
}
|
||
|
} catch (IOException e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
3 years ago
|
bb.writeLog("msgData:"+msgData);
|
||
3 years ago
|
return msgData;
|
||
|
}
|
||
|
|
||
|
}
|