获取在 $http.put 请求中传递的 Json 对象

Get Json object passed in $http.put request

我是 angularjs 的新手。我正尝试在 $http.put 请求中发送一个 json 对象,如下所示:

function LoginCtrl($http){
this.login = function(){
  var self = this;
        self.user = {
            username: this.username,
            password: this.password
        }
    $http.put('http://localhost:8086/app/login',self.user).then(function 
successCallback(response) {
      }, function errorCallback(response) {
      })
}
}

我只想在Restapi中得到这个json对象,其代码如下: @Path("/应用程序") public class 登录资源 {

public LoginResource() {
}

@PUT
@Path("/login")
@Consumes(MediaType.APPLICATION_JSON)
public Response getUserByName() {
    return Response.status(Response.Status.ACCEPTED).build();
}

我需要将哪些参数传递给此 getUserByName api?。我正在使用 dropwizard

此外,如果有人可以告诉我们如何将 index.html 页面设置为码头服务器配置中的起始页面。

首先,在您的 Dropwizard(Jersey) 后端定义您的输入

public Response getUserByName(User user) { ...

然后您可以将 JSON 映射到这样的实体:

public class User {
   @JsonProperty("name") 
   private String name; }

在 angularJS 中将 Json 对象作为请求负载传递到 $http.PUT(uri,<JsonObject>)

http.put(url, JSON.stringify(self.user), function (err, response) 
{
    // do something here
}