
org.johnnei.enjin.internal.http.impl.HttpAccessImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of enjin-api-impl Show documentation
Show all versions of enjin-api-impl Show documentation
The specification of the Enjin API
The newest version!
package org.johnnei.enjin.internal.http.impl;
import java.io.IOException;
import org.johnnei.enjin.internal.gson.GsonFactory;
import org.johnnei.enjin.internal.http.IHttpAccess;
import com.google.gson.Gson;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
public class HttpAccessImpl implements IHttpAccess {
private OkHttpClient client;
private Gson gson;
public HttpAccessImpl() {
client = new OkHttpClient();
gson = GsonFactory.create();
}
@Override
public String getString(String url, Object postData) throws IOException {
String postString = gson.toJson(postData);
Request request = new Request.Builder()
.url(url)
.post(RequestBody.create(MediaType.parse("application/json"), postString))
.build();
try (ResponseBody response = client.newCall(request).execute().body()) {
return response.string();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy