package cc.mrbird.febs.dapp.service.impl;
|
import okhttp3.*;
|
import com.google.gson.Gson;
|
import com.google.gson.JsonParser;
|
import java.io.IOException;
|
|
public class GraphQLClient {
|
|
private static final String ENDPOINT = "https://bsc-mainnet.nodereal.io/v1/fcb1ae31845147dcabb183db57336218";
|
// private static final String ENDPOINT = "https://open-platform.nodereal.io/fcb1ae31845147dcabb183db57336218/pancakeswap/graphql";
|
private static final OkHttpClient client = new OkHttpClient();
|
public static void main(String[] args) throws IOException {
|
|
MediaType mediaType = MediaType.parse("application/json");
|
RequestBody body = RequestBody.create(mediaType,
|
"{\"id\":1," +
|
"\"jsonrpc\":\"2.0\"," +
|
"\"params\":[\"0xcebfd36e03bd80c7015cbad17effbc33d2923ff3\",\"pending\"]," +
|
"\"method\":\"eth_getBalance\"}");
|
Request request = new Request.Builder()
|
.url(ENDPOINT)
|
.post(body)
|
.addHeader("accept", "application/json")
|
.addHeader("content-type", "application/json")
|
.build();
|
|
// Response response = client.newCall(request).execute();
|
try {
|
Response response = client.newCall(request).execute();
|
if (response.isSuccessful()) {
|
String responseBody = response.body().string();
|
// 在这里处理响应体,比如解析JSON数据等
|
System.out.println(responseBody); // 或者其他处理逻辑
|
} else {
|
// 处理请求失败的情况,比如输出错误信息、重试等
|
System.err.println("Request failed with code: " + response.code());
|
}
|
} catch (IOException e) {
|
// 处理网络异常、超时等异常情况
|
e.printStackTrace(); // 或者其他异常处理逻辑
|
}
|
}
|
}
|