Postman Java code snipped Okhttp not compatible

Viewed 508

I'm using Postman version 8.5.1 and I'm trying to use the code OkHTTP code snippets. It seems some statements are not working like ...

OkHttpClient client = new OkHttpClient().newBuilder().build();

However this seems to work ...

OkHttpClient client = new OkHttpClient();

Also this doesn't work ...

  .addFormDataPart("file","test.jpg",RequestBody.create(MediaType.parse("application/octet-stream"),new File("/Users/tm/Desktop/test.jpg")))

It mentions something about a wrong RequestBody object ...

I'm using this maven repo ...

    <dependency>
        <groupId>com.squareup.okhttp</groupId>
        <artifactId>okhttp</artifactId>
        <version>2.7.5</version>
    </dependency>

This is the import statement

 import com.squareup.okhttp.*;

What version of the okhttp is fully compatible with the Postman code snippets? Which maven repo should be used?

It seems there is also a okhttp3 ...

2 Answers

It seems the code snippets are okhttp3 and not okhttp...

This seems to work ...

    <dependency>
        <groupId>com.squareup.okhttp3</groupId>
        <artifactId>okhttp</artifactId>
        <version>4.9.1</version>
    </dependency>

import statement

 import okhttp3.*;
Related