gpt4 book ai didi

java.io.EOFException : End of input at line 1 column 1 path $ in Android retrofit 异常

转载 作者:搜寻专家 更新时间:2023-11-01 08:27:28 60 4
gpt4 key购买 nike

我正在使用 Retrofit 来使用 REST API 端点,但我遇到了以下问题。我认为 TransactionResponse 类的数据模型有问题,但还不确定。

java.io.EOFException: End of input at line 1 column 1 path $ in Android retrofit

我的调用请求如下。

 @FormUrlEncoded
@POST("/ifapi.php")
Call<TransactionResponse> loadData(@Field("user") TransactionRequest user);

交易请求类:

import javax.annotation.Generated;

@Generated("org.jsonschema2pojo")

public class TransactionResponse {

private Settings settings;
/**
*
* @return
* The settings
*/

public Settings getSettings()
{
return settings;
}
/**
*
* @param settings
* The settings
*/

public void setSettings(Settings settings)
{
this.settings = settings;
}

private Actions actions;
/**
*
* @return
* The actions
*/
public Actions getActions()
{
return actions;
}
/**
*
* @param actions
* The actions
*/
public void setActions(Actions actions)
{
this.actions = actions;
}
}

下面是调用实际完成的代码。

OkHttpClient httpClient = new OkHttpClient.Builder().build();
Retrofit retrofit = new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create()).baseUrl(
RestAPI.BASE_URL).client(httpClient).build();
RestAPI service = retrofit.create(RestAPI.class);
Call<TransactionResponse> meResponse = service.loadData(request);

meResponse.enqueue(new Callback<TransactionResponse>() {
@Override
public void onResponse(Call<TransactionResponse> call, Response<TransactionResponse> response) {
if (response.isSuccessful()) {
TransactionResponse body = response.body();
Actions actions = body.getActions();
Map<String, String> params = actions.getParams();
}
}

@Override
public void onFailure(Call<TransactionResponse> call, Throwable t){
t.printStackTrace();
}
});

谁能帮帮我?提前致谢。

我正在使用以下库。

compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'javax.annotation:javax.annotation-api:1.2'
compile 'com.squareup.retrofit2:converter-gson:2.2.0'

P.S 我发现该请求适用于表单数据,但不适用于 JSON 数据。 enter image description here

最佳答案

我找到了解决方案,您需要以如下形式发布每个参数,而不是在包装类中。

@FormUrlEncoded

@POST("/ifapi.php")

Call<TransactionResponse> loadData(@Field("app_id") String app_id, @Field("install_id") String install_id, @Field("useragent") String useragent, @Field("ip") String ip, @Field("mccmnc") String mccmnc, @Field("action") String action );

对于主要 Activity 部分。

OkHttpClient httpClient = new OkHttpClient.Builder().build();
Gson gson = new GsonBuilder()
.setLenient()
.create();
Retrofit retrofit = new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create(gson)).baseUrl(RestAPI.BASE_URL).client(httpClient).build();

RestAPI service = retrofit.create(RestAPI.class);
Call<TransactionResponse> meResponse = service.loadData("1", getUUID(), getUserAgent(), getIPAddress(), "20404", "start");

希望这能解决您的问题,此致。

关于java.io.EOFException : End of input at line 1 column 1 path $ in Android retrofit 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43444871/

60 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com