Comments (10)
Here's a test case showcasing that it can work:
retrofit/retrofit/src/test/java/retrofit2/RequestFactoryTest.java
Lines 2608 to 2621 in 23d0461
Please supply a failing test case if you think something is broken.
from retrofit.
I think this simple test may be not sufficient.
I have seem a lot of question on why field is not working.
no one can give a working answer.
I am now using okhttpclient instead.
from retrofit.
this is the code working with OkHttpClient:
public String quota(String username , String password) {
RequestBody formBody = new FormBody.Builder()
.add("username", username)
.add("password", password)
.build();
Request request = new Request.Builder()
.url(BASE_URL + "user/quota")
.post(formBody)
.build();
Call call = httpClient.newCall(request);
try {
Response response = call.execute();
return response.body().string();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
from retrofit.
this is the code not working with retrofit2:
public Quota quota;
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
public void start(String username, String password) {
Gson gson = new GsonBuilder()
.setLenient()
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.client(httpClient.build())
.build();
APIService apiService = retrofit.create(APIService.class);
Call<Quota> quotaCall = apiService.getQuota(username, password);
quotaCall.enqueue(this);
}
@Override
public void onResponse(Call<Quota> call, Response<Quota> response) {
if (response.isSuccessful()) {
quota = response.body();
} else {
System.out.println(response.errorBody());
}
}
@Override
public void onFailure(Call<Quota> call, Throwable t) {
t.printStackTrace();
}
public interface Quota {
public String username = "";
public int quota = 0;
public int upload = 0;
public int download = 0;
}
public interface APIService {
@GET("servers")
void getServers();
@FormUrlEncoded
@POST("user/quota")
Call<Quota> getQuota(@Field("username") String username, @Field("password") String password);
}
from retrofit.
How is it not working?
from retrofit.
How is it not working?
I can't trace much deeper.
I only know that the parameters are passed into the requester.
from retrofit.
https://github.com/Free-Web-Movement/android-base-library
this is a repository can reproduce this bug.
Where OKHTTP works well and @field not .
from retrofit.
Retrofit's @FormUrlEncoded
uses OkHttp's FormBody.Builder
to build the body the same as your snippet does.
retrofit/retrofit/src/main/java/retrofit2/RequestBuilder.java
Lines 89 to 91 in 87e0c81
I need a self-contained test case to debug anything here, so I'm going to preemptively close. If you can come up with a failing test case I can take a look.
from retrofit.
this is the failing test case and you don't take a look.
And there is only one test!
from retrofit.
https://github.com/Free-Web-Movement/android-base-library
is the simplest example that showing how @field fails.
if you don't have the ability to debug, then you'd better resign or close source this project.
from retrofit.
Related Issues (20)
- Do I need to mention the coroutine dispatcher while working with Retrofit?
- converter-kotlinx-serialization artifact is missing HOT 2
- Better support for redirects in Response class HOT 3
- java.util
- Retrofit ignores a moshi JsonAdapter
- How to send GET Request with JSON body? HOT 3
- How to hide sensitive information from response header? HOT 3
- [Android 14]{less than 14 i know how to do that}Can somebody here help me with how to pick file from file picker and then convert that to byte array and send it with retrofit post request . HOT 1
- JDK test tasks do not have dependencies set up correctly
- [Bug?] When the http request executes finished. The coroutine scope still alive. HOT 1
- Feature Request - Upgrade to okhttp3 version 4.x.y HOT 1
- Security issue: Information Exposure HOT 1
- Getting message as empty when response is not successful HOT 1
- Hi,Will there be a release version? HOT 1
- Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.5.1. HOT 2
- retrofit2.adapter.rxjava2.HttpException at BodyObservable.java:54 HOT 1
- Object cannot be cast to class retrofit2.ServiceMethod HOT 1
- Exception on api calling with Okhttp HOT 1
- ./> The first request to any backend takes as long as the connectTimeout is defined (5 seconds). Any subsequent calls go then really fast. Why is the first call waiting until the timeout exceeds before it succeeds?
- Unable to build project HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from retrofit.