Ответ на модернизацию - это html-код

Я работаю с модификацией 2 для подключения к веб-сервису в android studio 3.0, и у меня есть подобный запрос

@POST("clip/clipmobile/action/clike/clipId/{id}/token/{token}/app/21")
Call<ResponseBody> likeRequest(
    @Path("id") String id,
    @Path("token") String token);

и я моя инициализация модернизации:

 retrofitInterface = RetrofitClient.getClient(BASE_URL).create(RetrofitInterface.class);

и метод getClient ():

    if (retrofit == null) {
        retrofit = new Retrofit.Builder()

                .baseUrl(baseUrl)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .build();
    }
    return retrofit;

запрос на почтальона в порядке, но в android resposne.body (). string () получает html-код, подобный этому

<!DOCTYPE html>

<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "fa" lang = "fa" dir = "ltr">
<head>
    <title>
        نشر دیجیتال :: default    </title>
    <meta name = "samandehi" content = "456331049" />
    <link rel = "icon" href = "http://ndigi.ir/images/File/nashr-hamrah-logo.ico" />

    <meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" />
    <!-- <meta http-equiv = "Content-Language" content = "{currLang}" /> -->
    <meta name = "keywords" content = "pear, php, framework, cms, content management" />
    <meta name = "description" content = "Coming soon to a webserver near you." />
    <meta name = "rating" content = "General" />
    <meta name = "viewport" content = "width=device-width, initial-scale=1" />
    <meta name = "madeby" content = "Made by Artimanstudio" />
        <meta name = "robots" content = "index,follow" />        <meta name = "googlebot" content = "index,follow" />    <!-- <meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" /> -->

    <meta name = "copyright" content = "Copyright (c) 2008 نشر دیجیتال" />
    <meta name = "robots" content = "noodp,noydir" />
    <meta property = "og:locale" content = "fa_IR" />
    <meta property = "og:title" content = " نان و نمک" />
    <meta property = "og:description" content = "" />
    <meta property = "og:url" content = "" />
    <meta property = "og:site_name" content = "نان و نمک" />
    <meta property = "og:type" content = "article" />
    <meta property = "og:image" content = "" />

да ладно, тогда с какой проблемой вы столкнулись и что вы пытались для этого

Sachin 08.04.2018 09:28

@Thunder, я надеюсь дать мне json для его рендеринга

amirhesni 08.04.2018 09:30

да, это из вашего Backend, вам нужно проконсультироваться с вашим членом Backend Team, который пишет этот API, прямо сейчас этот api не возвращает ответ как JSON, поэтому вы не получаете

Sachin 08.04.2018 09:31

@Thunder, но на почтовом ящике он дал мне json-запросы, все еще с моей задней стороны ???

amirhesni 08.04.2018 09:33

хорошо, вам не хватает передачи application / json в заголовках

Sachin 08.04.2018 09:44

@Thunder, спасибо, все работает нормально

amirhesni 08.04.2018 09:54

хорошо добро пожаловать

Sachin 08.04.2018 10:26
2
7
4 545
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

Возможно, вам потребуется добавить заголовок acceptapplication/json к вашему запросу. Почтальон обычно добавляет в заголовок accept:"*/*". Это можно увидеть, открыв "Показать консоль почтальона" в почтальоне, а затем выполнив свой запрос.

т.е.

@POST("clip/clipmobile/action/clike/clipId/{id}/token/{token}/app/21")
Call<ResponseBody> likeRequest(
    @Header("accept") String type,
    @Path("id") String id,
    @Path("token") String token);

тогда позвони

likeRequest("application/json", id, token)

Другие вопросы по теме