我试图在Android上使用OKHttp发布帖子请求。我看了几个例子,这就是我构建的
OkHttpClient client = new OkHttpClient();
String url = "http://127.0.0.1:8080/test";
RequestBody body = new FormBody.Builder()
.add("access_token", "test")
.add("name", "David")
.build();
但是Builer
在Android工作室中是红色的,如果我将鼠标悬停在它上面,它会说"无法解析符号' Builder'"
以下是我的导入
import android.content.Context;
import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import java.io.IOException;
我的依赖
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
compile 'com.google.firebase:firebase-messaging:11.8.0'
compile 'com.klinkerapps:android-smsmms:4.3.0'
}
答案 0 :(得分:1)
请更新您的导入。
使用此
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;