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.
51 lines
1.4 KiB
Java
51 lines
1.4 KiB
Java
package com.customization.sendtodo;
|
|
|
|
import com.sun.jersey.core.util.Base64;
|
|
import okhttp3.*;
|
|
import weaver.general.BaseBean;
|
|
import java.io.IOException;
|
|
|
|
public class HttpReqUtils extends BaseBean{
|
|
|
|
/***
|
|
*
|
|
* @param dataJson
|
|
* @return
|
|
*/
|
|
public String doPostByAuth2(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;
|
|
}
|
|
|
|
}
|