插入更新时间
parent
4bd9fc00bb
commit
8446d91715
@ -0,0 +1,51 @@
|
||||
package weaver.interfaces.job.util;
|
||||
|
||||
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 static 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();
|
||||
|
||||
bb.writeLog("response.code():"+response.code());
|
||||
bb.writeLog("response.body():"+response.body().string());
|
||||
|
||||
if(response!=null && response.code() == 200){
|
||||
msgData = response.body().string();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return msgData;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue