用Postman测一个接口的时候,返回了405,百度搜,都说把post请求改成get就可以了,但是,代码是这样的 。(公司前辈写的,我只是按要求改了中间的一个小细节)
@GetMapping("getPlayHistoryInfo")
public String getLivePlayHistoryInfo(
@RequestParam("usertoken") String usertoken,
@RequestParam("userid") String userid,
@RequestParam("cpspid") int cpspid,
@RequestParam("parent") int parent,
@RequestParam("videoencryption") int videoencryption,
@RequestParam("action") int action) {
JSONObject object = new JSONObject();
BookMarkBean liveVodBean = new BookMarkBean();
liveVodBean.setUserId(userid);
liveVodBean.setMediaType(2);
try {
if (action == 0) {
List<LiveBean> list = bookMarkService.getBookMarkInfoByUserId(liveVodBean);
List<LiveBean> liveList = getChannelList(list, usertoken, parent, videoencryption, cpspid, userid);
object.put("playInfo", JSONArray.fromObject(liveList).toString());
} else if (action == 1) {
List<VodBean> vodlList = bookMarkService.getVodInfoByUserId(liveVodBean);
List<VodBean> vodList = getProgramList(vodlList, usertoken, parent, videoencryption, cpspid, userid);
object.put("playInfo", JSONArray.fromObject(vodList).toString());
}
object.put("returnCode", 0);
} catch (Exception e) {
e.printStackTrace();
object.put("returnCode", -1);
}
return object.toString();
}
我一看这代码,不是post啊,找了蛮久蛮久蛮久,然后分步输出,才发现是getProgramList方法这里报的错,跟进去,发现这个方法里面又调用了另外一个方法,再跟进去!
public String getVodPlayUrl(String usertoken, int pid, String userid, int seriesId) {
String url = "http://vod/getVodPlayUrl?usertoken=" + usertoken + "&pid=" + pid + "&mediaType=1" + "&userid=" + userid + "&seriesId=" + seriesId;
return restTemplate.postForEntity(url, String.class, String.class).getBody();
}
终于发现post在哪了,把最后一句return 换成
return restTemplate.getForEntity(url, String.class).getBody();
就能正常走下去了