Reputation: 459
I am working with retrofit 2 for connecting to web service on android studio 3.0 and i have a like request like this
@POST("clip/clipmobile/action/clike/clipId/{id}/token/{token}/app/21")
Call<ResponseBody> likeRequest(
@Path("id") String id,
@Path("token") String token);
and i my retrofit init:
retrofitInterface = RetrofitClient.getClient(BASE_URL).create(RetrofitInterface.class);
and getClient() method :
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}
return retrofit;
request on postman is fine but in android resposne.body().string() gets a html code like this
<!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="" />
Upvotes: 2
Views: 8298
Reputation: 1705
You might need to add the accept
header of application/json
to your request. postman usually adds in accept:"*/*"
header. Can see this by opening up 'Show Postman Console' in postman then running your request
i.e.
@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);
then call
likeRequest("application/json", id, token)
Upvotes: 2