简体   繁体   English

如果请求实体的内容类型不是application / x-www-form-urlencoded,则使用@FormParam。

[英]The @FormParam is utilized when the content type of the request entity is not application/x-www-form-urlencoded]

I'm trying to create a simple login feature for my website. 我正在尝试为我的网站创建一个简单的登录功能。 I'm using JAVA as backend and I'm trying to use restservices. 我正在使用JAVA作为后端,并且正在尝试使用restservices。 My school gave me an example of a login system with authication. 我的学校给了我一个带有身份验证的登录系统的示例。 Unfortunately I'm getting this error: java.lang.IllegalStateException: The @FormParam is utilized when the content type of the request entity is not application/x-www-form-urlencoded]. 不幸的是,我收到此错误:java.lang.IllegalStateException:当请求实体的内容类型不是application / x-www-form-urlencoded时,将使用@FormParam。

 @POST
 @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
 public Response authenticateUser(@FormParam("username") String username,
 @FormParam("password") String password) {

 <form id='inlogForm' enctype="application/x-www-form-urlencoded" >
    <input type='text' placeholder='username' id='username' />
    <input type='text' placeholder='password' id='password' />
    <input type='button' value='login' id='login' />
    </form>
    </header>   
</body>
<script src="https://code.jquery.com/jquery-3.2.0.min.js"></script>
<script>
    $("#login").click(function(event) {
        var data = $("#loginForm").serialize();
        $.post("restservices/authentication", data, function(response) {
            window.sessionStorage.setItem("sessionToken", response);
            $("#loginForm").hide();
        }).fail(function(jqHXR, textStatus, errorThrown) {
            console.log(textStatus);
            console.log(errorThrown);
            alert("Wrong Username/Password")
        });
    });

From the looks of it, you should be using @FormDataParam instead of @FormParam . 从外观@FormDataParam ,您应该使用@FormDataParam而不是@FormParam

I found it here: https://groups.google.com/forum/#!topic/dropwizard-user/bYyG-Pvk29Y , but still don't quite understand the reasoning. 我在这里找到它: https : //groups.google.com/forum/#!topic/dropwizard-user/bYyG-Pvk29Y ,但仍然不太了解其原因。

暂无
暂无

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

相关问题 当我的dataType:“ JSON”时,为什么我的Ajax请求发送“内容类型:application / x-www-form-urlencoded”? - Why is my Ajax request sending “Content-Type: application/x-www-form-urlencoded” when I have dataType: “JSON”? 使用字符串作为请求正文时,为什么 Axios 发送我的 POST 请求时使用 Content-Type application/x-www-form-urlencoded? - Why does Axios send my POST request with Content-Type application/x-www-form-urlencoded when using a string as the request body? 使用内容类型为 application/x-www-form-urlencoded 的 POST Fetch 调用时,从服务器返回的本机 422 不可处理实体错误 - React native 422 Unprocessable Entity error returned from server when using POST Fetch call with content type: application/x-www-form-urlencoded Ajax请求:application / x-www-form-urlencoded参数 - Ajax request : application/x-www-form-urlencoded params "ajax、setRequestHeader()、Content-Type、application\/x-www-form-urlencoded 和 charset" - ajax, setRequestHeader(), Content-Type, application/x-www-form-urlencoded and charset 无法通过“Content-Type”发送 JSON object:“application/x-www-form-urlencoded - Unable to send JSON object over “Content-Type”: "application/x-www-form-urlencoded 如何使发布请求具有bas ic auth和内容类型x-www-form-urlencoded - how to make post request baswith ic auth and content type x-www-form-urlencoded 如何在+呼叫后内容类型中转义+作为application / x-www-form-urlencoded - How to escape + in post call content type as application/x-www-form-urlencoded file_get_contents():假设应用程序/x-www-form-urlencoded 未指定内容类型 - file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded HttpMediaTypeNotSupportedException:不支持内容类型 'application/x-www-form-urlencoded;charset=UTF-8' - HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM