package com.baidu.dev2.sdk;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import java.io.IOException;
public class Dev2Example {
public static final MediaType JSON = MediaType.get("application/json; charset=utf-8");
private OkHttpClient client = new OkHttpClient();
public static void main(String[] argcs) throws IOException {
String json = "{\"header\":{\"accessToken\":\"ayJhbGciOiJIUzM4NCJ9.eyJzdWIiOiJhY2MiLCJhdWQiOiLpk4Hlsq3ljY_kvbMiLCJ1aWQiOjMzMjk5MTM5LCJhcHBJZCI6ImM3MGEyMGM3NGRiN2ExMDgwZDhhOGFjNjIwMzM5NzE3IiwiaXNzIjoi5ZWG5Lia5byA5Y-R6ICF5Lit5b-DIiwicGxhdGZvcm1JZCI6IjQ5NjAzNDU5NjU5NTg1NjE3OTQiLCJleHAiOjQxMDI0MTYwMDAsImp0aSI6Ijc0OTU4NDQ4Mjc4NjYyOTIyNTMifQ.4a2CN0WNs9JCKJMFaEPf-Q8-g_IM1iTCb5XfYNg9fiDV2gRhneUyC8_wSqGCJFiN\",\"userName\":\"BDCC-超级管家\",\"action\":\"API-JAVA\"},\"body\":{\"mccid\":null}}";
String url = "https://api.baidu.com/json/feed/v1/MccFeedService/getUserListByMccid";
Dev2Example dev2Example = new Dev2Example();
String result = dev2Example.post(url, json);
System.out.println(result);
}
private String post(String url, String json) throws IOException {
RequestBody body = RequestBody.create(json, JSON);
Request request = new Request.Builder().url(url).post(body).build();
try (Response response = client.newCall(request).execute()) {
return response.body().string();
}
}
}
我试了我自己能尝试的几个办法都不行,都只能返回The Json message you provided is invalid.please check the request json,说我json无效。
我看py和java那个mccid的值不一样两个都试也不行,URL编码了里面的汉字也不行,这个怎么提交谁能给个例子