0
Я новичок в модернизации, и я пытаюсь реализовать модифицированный проект.Отправка параметров POST - Модернизация
Я использую метод POST, и переходя в теле: { «текст„:“SURC»} Но ничего не приходит на сервер и дает мне ошибку
Data.class
public class Data {
String text;
public Data(String text) {
this.text = text;
}
}
Интерфейс
public interface RecordService {
@POST("/test")
void post(@Body Data data, Callback<List<Record>> callback);
}
Главная
RequestInterceptor requestInterceptor = new RequestInterceptor() {
@Override
public void intercept(RequestFacade request) {
request.addHeader("Authorization",
"Bearer fb5JnZnlG3pyk3oaeSMNXRiuBHH2Abch8GwUhFPM");
}
};
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("http://api.pe/example")
.setRequestInterceptor(requestInterceptor)
.setLogLevel(RestAdapter.LogLevel.FULL)
.setLog(new RestAdapter.Log() {
@Override
public void log(String msg) {
Log.i("Log Retrofit", msg);
}
})
.build();
Data data = new Data("surc");
RecordService record = restAdapter.create(RecordService.class);
record.postUbigeo(data, new Callback<List<Record>>() {
@Override
public void success(List<Record> records, Response response) {
Log.i("dataaa success", response.toString());
}
@Override
public void failure(RetrofitError error) {
Log.i("dataaa failure", error.getMessage().toString());
}
});
Ошибка сервера
I/Log Retrofit: {"_meta":{"status":"ERROR"},"records":{"errorCode":1002,"userMessage":"Error Params","devMessage":[],"more":{"fields":{"text":"text is required"}},"applicationCode":[]}}
Log:
I/Log Retrofit: ---> HTTP POST http://api.pe/example/test
I/Log Retrofit: Authorization: Bearer fb5JnZnlG3pyk3oaeSMNXRiuBHH2Abch8GwUhFPM
I/Log Retrofit: Content-Type: application/json; charset=UTF-8
I/Log Retrofit: Content-Length: 16
I/Log Retrofit: {"text":"surc"}
I/Log Retrofit: ---> END HTTP (16-byte body)
I/Timeline: Timeline: Activity_idle id: [email protected] time:772594491
I/Log Retrofit: <--- HTTP 500 http://api.pe/example/test (421ms)
I/Log Retrofit: Server: nginx
I/Log Retrofit: Date: Wed, 02 Dec 2015 16:41:57 GMT
I/Log Retrofit: Content-Type: application/json
I/Log Retrofit: Content-Length: 172
I/Log Retrofit: Connection: keep-alive
I/Log Retrofit: X-Powered-By: PHP/5.4.21 ZendServer/6.2.0
I/Log Retrofit: Set-Cookie: ZDEDebuggerPresent=php,phtml,php3; path=/
I/Log Retrofit: Set-Cookie: PHPSESSID=aemfb488cu0bk5n05i7ug45ak1ia94cg; path=/
I/Log Retrofit: Expires: Thu, 19 Nov 1981 08:52:00 GMT
I/Log Retrofit: Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
I/Log Retrofit: Pragma: no-cache
I/Log Retrofit: Status: 1002 Input Parameter not valid
I/Log Retrofit: E-Tag: 1e9672f97d6b00dace015a629dcb67ec
I/Log Retrofit: OkHttp-Selected-Protocol: http/1.1
I/Log Retrofit: OkHttp-Sent-Millis: 1449074516360
I/Log Retrofit: OkHttp-Received-Millis: 1449074516514
I/Log Retrofit: {"_meta":{"status":"ERROR"},"records":{"errorCode":1002,"userMessage":"Error Params","devMessage":[],"more":{"fields":{"text":"text is required"}},"applicationCode":[]}}
I/Log Retrofit: <--- END HTTP (172-byte body)
I/dataaa failure: 500 Internal Server Error
I/Timeline: Timeline: Activity_idle id: [email protected] time:772595639
Почтальон:
Спасибо за вашу помощь.
Пожалуйста, ваш код. –
Я забыл, но добавляю код – Woz
Почему бы не использовать '@Field (" text ") String yourText'? –