package com.monkey.api;
import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import com.google.gson.JsonObject;
public class TestMzonUserConfirm {
public static void main(String[] args) throws ClientProtocolException, IOException {
String url = "url";
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost post = new HttpPost(url);
post.setHeader("content-type", "application/json;charset=UTF-8");
//配置json数据
JsonObject json = new JsonObject();
json.addProperty("opToken", "5ris7rUX4P29u15TlWH.Se");
json.addProperty("mp", "13911188896");
json.addProperty("smsCode", "503540");
json.addProperty("deviceId", "515fa8cace574187e4ddae1e169dfc15");
json.addProperty("appId", "100001");
StringEntity entity = new StringEntity(json.toString(), "UTF-8");
post.setEntity(entity);
//发送请求
HttpResponse response = httpclient.execute(post);
//获取响应吗
HttpEntity entity2 = response.getEntity();
System.out.println(EntityUtils.toString(entity2));
}
}
现在公司所用的一个接口,为了避嫌,所以删除了某些关键信息。