I'd like to use the OkHttp library in an existing Javafx project. I'm using Netbeans and I've imported the OkHttp jar into the project but I'm not sure how to use. Also, is it possible to include only portions of the lib instead of the entire jar? Either way, how to I add it to my existing project? I assume its some type of import
but I'm not sure.
Asked
Active
Viewed 2,327 times
2

user1491929
- 654
- 8
- 16
1 Answers
1
Assuming the including of the JAR went OK, then an example of how to use it can be found on the site of OkHttp:
// https://raw.githubusercontent.com/square/okhttp/master/samples/guide/src/main/java/okhttp3/guide/GetExample.java
import java.io.IOException;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class GetExample {
OkHttpClient client = new OkHttpClient();
String run(String url) throws IOException {
Request request = new Request.Builder()
.url(url)
.build();
try (Response response = client.newCall(request).execute()) {
return response.body().string();
}
}
public static void main(String[] args) throws IOException {
GetExample example = new GetExample();
String response = example.run("https://raw.github.com/square/okhttp/master/README.md");
System.out.println(response);
}
}

Bart Kiers
- 166,582
- 36
- 299
- 288