我有一個改造的對象是這樣的:發送兩個字符串項作爲身體改造
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
和
@Headers
({
"Content-Type: application/x-www-form-urlencoded",
"cache-control: no-cache"
})
@POST("login")
Call<RegisterResponse> register(@Body String n1,@Body String n2);
,我知道那是因爲兩個身上標註不正確。
所以我必須使用此代碼
@Headers
({
"Content-Type: application/x-www-form-urlencoded",
"cache-control: no-cache"
})
@POST("login")
Call<RegisterResponse> register(@Body TestObject testObject);
class TestObject{
String n1;
String n2;
}
,但我有我不能改變它,它得到兩個參數作爲身體的服務器。
當我使用郵遞員我的服務器工作得很好,做它應該做的。
但是當我使用改裝我得到一個錯誤500「服務器內部錯誤」
我與okhttp
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "n1=09369&n2=145616");
Request request = new Request.Builder()
.url(URL)
.post(body)
.addHeader("content-type", "application/x-www-form-urlencoded")
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "0761ac45-1fb7-78df-d088-2437ecb984a3")
.build();
okhttp3.Response response = client.newCall(request).execute();
及其作品不錯,但我怎麼能與改造做到這一點做到了這一點?
'當我使用郵遞員我的服務器工作得很好'你到底有多使用它?你通過2個身體哪裏通過? –
在郵差我只有一個身體標籤,我添加兩個參數在它 – max
然後做同樣的 - 添加2個參數。沒有設置身體。 –