415当ResponseEntity <map <string,string =“”>&gt;时,不支持的媒体类型响应

时间:2017-06-03 06:34:24

标签: java resttemplate

我在尝试获得以下回复时遇到以下错误。

var data11 = (from p in db.FeePlan.Where(d => d.AcademicYearID == dts.AcademicYearID && d.Active == true && d.IsEffectiveDates == false)
              from fb in db.FeePlansToBranches.Where(x => x.FeePlanID == p.FeePlanID && x.BranchID == BranchID)
              from b in db.Branches.Where(b => b.BranchID == fb.BranchID)
              from fp in db.AssignFeeplanToClasses.Where(a => a.BranchID == BranchID && a.ClassID == ClassID && a.FeePlanID == p.FeePlanID)
              from cl in db.Classes.Where(c => c.ClassID == fp.ClassID)
              select new
                     {
                         p.FeePlanName,
                         p.FeePlanID,
                         b.BranchName,
                         cl.ClassName,
                         fp.AssignFeeplanToClassID,
                         fp.CreatedDate
                     }).Distinct().ToList();

var data2 = (from p in db.FeePlan.Where(d => d.AcademicYearID == dts.AcademicYearID && d.Active == true &&d.IsEffectiveDates == true)
             from fb in db.FeePlansToBranches.Where(x => x.FeePlanID == p.FeePlanID && x.BranchID == BranchID)
             from b in db.Branches.Where(b => b.BranchID == fb.BranchID)
             from fp in db.AssignFeeplanToClasses.Where(a => a.BranchID == BranchID && a.ClassID == ClassID && a.FeePlanID == p.FeePlanID)
             from cl in db.Classes.Where(c => c.ClassID == fp.ClassID)
             where (DateTime.Now> p.StartDate && DateTime.Now < p.EndDate)
             select new
                    {
                        p.FeePlanName,
                        p.FeePlanID,
                        cl.ClassName,
                        b.BranchName,
                        fp.AssignFeeplanToClassID,
                        fp.CreatedDate
                    }).Distinct().ToList();

js.Data = data11.Union(data2);

我正在使用基本身份验证,我的标题包含以下内容,

private static final ParameterizedTypeReference<Map<String, String>> mapTypeReference = new ParameterizedTypeReference<Map<String, String>>() {
    };


ResponseEntity<Map<String, String>> response = restTemplate.exchange(url, HttpMethod.POST, new HttpEntity<Object>(httpHeaders), mapTypeReference);

错误:

httpHeaders.add("someid", "1234");
        httpHeaders.add("someid2", "222");
        httpHeaders.add("Content-Type","text/xml"); // i tried application/json as well 
        httpHeaders.add("Accept","text/xml"); // i tried application/json as well

1 个答案:

答案 0 :(得分:0)

对于ContentType和Accept标头,您也可以使用此方法:

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON);