1
json-rpc
をretrofit2
で送信しようとしました。 これは私のインターフェイスです:retrofit2経由でJson-rpcを送信するには?
public interface ApiInterfaceJson {
@POST
@Headers("Content-Type: application/json")
Call<String> getDataJson(
@Url String url,
@Body RequestBody body);
}
はretrofit
を作成します。
retrofitJson = new Retrofit.Builder()
.addConverterFactory(ScalarsConverterFactory.create())
.baseUrl("http://localhost:8800")
.client(client)
.build();
apiInterfaceJson = retrofitJson.create(ApiInterfaceJson.class);
コール:
JSONObject paramObject = new JSONObject();
try {
paramObject.put("id", "0");
paramObject.put("name", "user");
paramObject.put("command", "finish");
}catch(Exception e){
}
RequestBody requestBody= RequestBody.create(MediaType.parse("application/json"), paramObject.toString());
MinersMonitorApplication.getApiJson().getDataJson("http://10.10.10.230:10000", requestBody).enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {}
@Override
public void onFailure(Call<String> call, Throwable t) {
}
});
結果はSocketTimeoutException
です。