저는 Android 용 클라이언트 - 서버 응용 프로그램을 작성하고 있습니다. 문제가있어서 추적 할 수 없습니다. 요점은 다음과 같습니다. API 메소드가 있습니다. 장치에서 POST 요청을 보냅니다 (그러나 서버에서 REQUEST 배열을 사용하기 때문에이 메서드는 무관심하며 Retrofit 2를 사용하여 동일한 GET을 사용하려고했습니다). 메서드는 포럼에 메시지를 게시한다고 가정합니다. 결과적으로 시간은 두 배가되고 시간은 두 배가됩니다. 나는 로그에서 요청을 받아 브라우저에 표시하고 장치에 표시되는 사용자 에이전트는 모든 것이 올바르게 작동하며 한 개의 게시물 만 게시됩니다.Android. 클라이언트 - 서버 응용 프로그램에서 메시지가 클라이언트에서 게시되면 복제됩니다.
개조 방법 :
@FormUrlEncoded
@POST("api/index.php?m=topic&action=send")
Observable<ApiResponse> sendPost(@Field("id_topic") long id,
@Field("subject") String subject,
@Field("message") String text);
방법 전화 :
public void sendPost(String subj, String text) {
Subscription subscription = model.sendPost(args.getLong("topic_id"), subj,
text)
.subscribe(new Observer<ApiResponse>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
try {
Log.e("Post wrong", "Error while posted message: " + e.getMessage());
activityCallback.makeToast("Message not published, an error occurred");
} catch (NullPointerException e1) {
Log.e("Error:", "getMessaage() or activityCallback is null");
}
}
@Override
public void onNext(ApiResponse apiResponse) {
try{
activityCallback.makeToast("Message successfully published");
} catch (NullPointerException e) {
Log.e("Error:", "activityCallback is null");
}
reload();
}
});
addSubscription(subscription);
}
온 클릭 : onclick을 정확히 회만이라고
@OnClick(R.id.sendButton)
public void send() {
if (sendText.getText() == null
|| sendText.getText().toString().trim().isEmpty()){
makeToast("Введите текст публикации");
return;
}
presenter.sendPost("Re: Тестовая тема", sendText.getText().toString());
}
. 로그에서 보았을 때 요청은 동일한 방식으로 한 번 전송됩니다. 무엇이 문제 일 수 있습니까? 제발, 도와주세요
당신은'addSubscription (subscription)'메소드의 코드도 게시 할 수 있습니까? – Schlangguru
나는 내 문제를 해결했다. 고마워! –