我正在使用改造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="" />
答案 0 :(得分:1)
您可能需要将accept
application/json
标题添加到您的请求中。邮递员通常会添加accept:"*/*"
标题。通过打开Show Postman Console&#39;可以看到这一点。在邮递员然后运行您的请求
即
@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)