我正在开发一个 Fabric Minecraft mod,它将发送 http 请求。
这是我使用的代码:
import com.google.gson.JsonObject;
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.HttpClientBuilder;
import java.io.IOException;
public class NetworkUtils {
public static void post(String url, JsonObject json) throws IOException {
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpPost request = new HttpPost(url);
StringEntity params = new StringEntity(json.toString());
request.addHeader("content-type", "application/json");
request.setEntity(params);
httpClient.execute(request);
httpClient.close();
}
}
当我在开发环境中运行它时,它运行良好。但是,当我将其构建为 jar 文件并将其放入mods
实际服务器的文件夹中时,会产生以下错误:
java.lang.NoClassDefFoundError: org/apache/http/HttpEntity
我该如何解决?非常感谢你,如果你能帮忙