I am doing android, looking for a way to do a super basic http GET/POST request. I keep getting an error:
java.lang.IllegalArgumentException: Unable to creat
You can try the following:
build.gradle file:
dependencies {
...
compile 'com.squareup.retrofit2:retrofit:2.0.1'
...
}
WebAPIService:
@GET("/api/values")
Call getValues();
Activity file:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(API_URL_BASE)
.build();
WebAPIService service = retrofit.create(WebAPIService.class);
Call stringCall = service.getValues();
stringCall.enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) {
Log.i(LOG_TAG, response.body());
}
@Override
public void onFailure(Call call, Throwable t) {
Log.e(LOG_TAG, t.getMessage());
}
});
I have tested with my Web serivce (ASP.Net WebAPI):
public class ValuesController : ApiController
{
public string Get()
{
return "value1";
}
}
Android Logcat out: 04-11 15:17:05.316 23097-23097/com.example.multipartretrofit I/AsyncRetrofit2: value1
Hope it helps!