Cannot resolve symbol "FormBody" - okttp3 error

Viewed 1419

I am using okhttp3 to connect my android application to my mysql database but it gives me an error while using FormBody.Builder() (I see other using this method).

I need to execute a post request.

OkHttpClient client = new OkHttpClient();

     RequestBody formBody = new FormBody.Builder() //this FormBody gives "Cannot resolve symbol FormBody"
            .add("name", reg_name)
            .add("pass", reg_pass)
            .build();

     Request request = new Request.Builder()
            .url(reg_url)
            .post(formBody)
            .build();
1 Answers

It looks like you are using the wrong version of okhttp. Make sure your Gradle dependency is specified as follows:

compile 'com.squareup.okhttp3:okhttp:3.9.0'

(or most appropriate version number)

Also, be sure to include the appropriate import statement:

import okhttp3.FormBody;
Related