简体   繁体   English

角度与resteasy-Mediatype不支持的错误

[英]angular with resteasy - Mediatype unsupported error

I am trying to submit a form to the backend rest service from angularjs controller and getting unsupported media type even i submit the header with content type. 我正在尝试从angularjs控制器向后端rest服务提交表单,并获得不受支持的媒体类型,即使我使用内容类型提交标头也是如此。

Error : 错误:

Failed to load resource: the server responded with a status of 415 (Unsupported Media Type) 加载资源失败:服务器响应状态为415(不支持的媒体类型)

Angular controller : 角度控制器:

    $scope.formData = {
        'name':'test',
        'email':'test@test.com'
    };

    function get(restUrl, formData) {
    function success(result) {

        return result.data;
    }

    function error(err) {
        return err.data;
    }
    return $http({
        url: restUrl,
        headers: { 'Content-Type': 'application/json; charset=UTF-8'},
        method: "GET",
        timeout: 200000,
        params: formData
    }).then(success, error);
}

Java form class, Java表单类,

public class SearchForm {

    private String name;
    private String email;

    public SearchForm() {
        super();
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
}

Rest controller, 休息控制器

@Named
@Singleton
@Path("/api/v1/")
public class SearchController {

  @GET
    @Path("/getAll")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public List<ResultDto> getReconLogs(@Context final HttpServletRequest request, final SearchForm searchForm) {
}
}

Is there anything required in the Angular controller or any annotation in the form class? Angular控制器或表单类中的注释是否需要任何内容​​?

Thanks 谢谢

Server API or definition issue. 服务器API或定义问题。 Your client side is ok but not function success(result) { return result.data; } function error(err) { return err.data; } 您的客户端可以,但是不能function success(result) { return result.data; } function error(err) { return err.data; } function success(result) { return result.data; } function error(err) { return err.data; } function success(result) { return result.data; } function error(err) { return err.data; } promises are not used like this. function success(result) { return result.data; } function error(err) { return err.data; }诺言不是这样使用的。 You cannot return result.data from success or error. 您无法从成功或错误中返回result.data。 You have to assign or capture it or do some manipulations. 您必须分配或捕获它或进行一些操作。

Try this to set definitions: 试试这个来设置定义:

https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

Http 415 Unsupported Media type error with JSON HTTP 415 JSON不支持的媒体类型错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM