问题描述
发送带有改造的请求时出现异常。尝试了各种解决方案,每次都给出格式错误的异常。
package com.example.sananelazm.Models;
public class LoginPojo{
private Object userEmail;
private Object id;
public void setUserEmail(Object userEmail){
this.userEmail = userEmail;
}
public Object getUserEmail(){
return userEmail;
}
public void setId(Object id){
this.id = id;
}
public Object getId(){
return id;
}
@Override
public String toString(){
return
"LoginPojo{" +
"userEmail = '" + userEmail + '\'' +
",id = '" + id + '\'' +
"}";
}
}
RestApi 界面是这样的
package com.example.sananelazm.RestApi;
import com.example.sananelazm.Models.LoginPojo;
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
public interface RestApi {
@FormUrlEncoded
@POST("/ayar.PHP")
Call<LoginPojo> control(@Field("userEmail") String userEmail,@Field("userPassword") String userPassword);
}
像这样的 Restapiclient
package com.example.sananelazm.RestApi;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class Restapiclient {
private RestApi mRestApi;
public Restapiclient (String restApiServiceUrl){
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.readTimeout(30,TimeUnit.SECONDS)
.writeTimeout(30,TimeUnit.SECONDS)
.connectTimeout(3,TimeUnit.SECONDS);
OkHttpClient okHttpClient = builder.build();
Gson gson = new GsonBuilder()
.setLenient()
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(restApiServiceUrl)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
mRestApi = retrofit.create(RestApi.class);
}
public RestApi getRestApi(){
return mRestApi;
}
}
像这样的BaseUrl
package com.example.sananelazm.RestApi;
public class BaseUrl {
public static final String URL = "http://10.0.2.2/";
}
像这样的 BaseManager
package com.example.sananelazm.RestApi;
public class BaseManager {
protected RestApi getRestApi(){
Restapiclient restapiclient = new Restapiclient(BaseUrl.URL);
return restapiclient.getRestApi();
}
}
和经理都喜欢这个
package com.example.sananelazm.RestApi;
import com.example.sananelazm.Models.LoginPojo;
import retrofit2.Call;
public class ManagerAll extends BaseManager {
private static ManagerAll ourInstance = new ManagerAll();
public static synchronized ManagerAll getInstance() {
return ourInstance;
}
public Call<LoginPojo> login(String userEmail,String userPassword) {
Call<LoginPojo> x = getRestApi().control(userEmail,userPassword);
return x;
}
}
像这样摇篮
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
implementation 'com.google.code.gson:gson:2.6.1'
@H_502_45@我正在尝试在本地服务器上使用 xampp 执行此项目,但出现错误,您能帮我解决问题吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)