誰かが私を助けることができますか?私はポストメソッドでデータを送信するために2を使用していますが、3回送信します。改造2重複要求
ここに私のサービスジェネレータ:
public class ServiceGenerators {
private static final String TAG = ServiceGenerators.class.getSimpleName();
//private static HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
private static OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
private static Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl(Constant.API_URL)
.addConverterFactory(GsonConverterFactory.create());
public static <S> S createService(Class<S> serviceClass) {
//loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);/
httpClient.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request original = chain.request();
Response response = chain.proceed(original);
Log.e(TAG, original.url().toString());
Request.Builder requestBuilder = original.newBuilder()
.header("Access-key", "0c3ed6a45e33e047c4e3785cb87aa6b27e651c52")
.method(original.method(), original.body());
Request request = requestBuilder.build();
return chain.proceed(request);
}
});
OkHttpClient client = httpClient.build();
Retrofit retrofit = builder.client(client).build();
return retrofit.create(serviceClass);
}
}
Kejadianサービス
@FormUrlEncoded
@POST("/api/kejadian")
Call<Responses> postKejadian(
@Field("kejadian") String kejadian,
@Field("w_kejadian") String w_kejadian,
@Field("lokasi") String lokasi,
@Field("keterangan") String keterangan,
@Field("id_user") int id_user
);
ここに私のプロセス:
KejadianService service = ServiceGenerators.createService(KejadianService.class);
Call<Responses> call = service.postKejadian(kejadian.getText().toString(), tanggal, lokasi.getText().toString(), keterangan.getText().toString(), session.getUID());
call.enqueue(new Callback<Responses>() {
@Override
public void onResponse(Call<Responses> call, Response<Responses> response) {
pd.dismiss();
int code = response.code();
if (code == 200){
Responses responses = response.body();
if (responses.error == null) {
Constant.showDialog(getApplicationContext(), "Kejadian berhasil dikirim!", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
} else {
Snackbar.make(findViewById(R.id.drawer_layout), responses.error, Snackbar.LENGTH_LONG).show();
}
call.cancel();
}else if (code == 500){
Snackbar.make(findViewById(R.id.drawer_layout), "Error in server", Snackbar.LENGTH_LONG).show();
}
}
@Override
public void onFailure(Call<Responses> call, Throwable t) {
}
});
マイログ
06-26 06:27:39.640 17813-18294/E/ServiceGenerators:http // myurl/api/kejadian 06-26 06:27 I/System:core_booster、getBoosterConfig = false 06-26 06:27:40.070 17813-18294 E/ServiceGenerators:http // myurl/api/kejadian 06-26 06:27:40.070 17813-18294 I/System:core_booster、getBoosterConfig = false 06-26 06:27:40.520 17813から18294 E/ServiceGeneratorsます:http // myurl/API/kejadian 6月26日06:27:40.520 17813から18294 I /システム:core_booster、getBoosterConfig = falseを
私はあなたは私が何を意味するか理解してほしいです、ありがとう
ありがとうございます。 –