我制作了一个演示应用程序,rails new demo然后生成了一个脚手架用户控制器rails generate scaffold User name:string email:string.脚手架代码中有一个ApplicationController用protect_from_forgery,所以不会UserController从派生ApplicationController.
我运行webrick,添加一个用户,很酷.真实性令牌的工作方式与/ on上的POST一致.
然而,仍然使用Rails 3.0.5我能够做到:
niedakh@twettek-laptop:~$ telnet 10.0.0.4 3000
PUT /users/3 HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 39
user[name]=vvvvv&user[email]=shiaus.pl
Run Code Online (Sandbox Code Playgroud)
并且在不给出令牌的情况下修改用户3:
Started PUT "/users/3" for 10.0.0.4 at 2011-04-02 14:51:24 +0200
Processing by UsersController#update as HTML
Parameters: {"user"=>{"name"=>"vvvvv", "email"=>"shiaus.pl\r"}, "id"=>"3"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1
', "updated_at" = '2011-04-02 12:51:24.437267' WHERE "users"."id" = 3s.pl
Redirected to http://10.0.0.4:3000/users/3 …Run Code Online (Sandbox Code Playgroud) 以下代码:
class Message(db.Model):
content = db.StringProperty()
class Message(webapp2.RequestHandler):
def get(self):
doRender(self,'message.htm')
def post(self):
message = Message()
message.content = self.request.get('content')
message.put();
self.redirect('/view')
Run Code Online (Sandbox Code Playgroud)
给我以下错误消息:
AttributeError: 'Message' object has no attribute 'put'
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
((我也在 Unity Answers 和 GameDev 上发布了此内容,但在此发布 x-posting 以防任何 C# 网络负责人可以指出我的 HttpWebRequest 代码中的任何明显错误...))
我正在尝试通过他们的 SDK 将通过我的游戏捕获的图像发布到 Facebook,并且由于它需要一个 URI,我编写了一个简单的 AWS Lambda 函数来获取一个字节数组并将其上传到 AWS 存储桶。AWS 函数接受一个调用,然后返回一个 URL 以使用图像数据调用 PUT ......所以这个想法是,如果响应是 200,使用该 URL 发布到 FB。
但是 - 使用 Unity 5.2.x 到 5.3.4 和 Android 4.4 - 6.1 - 它总是给我 403 响应,同时在 iOS 上工作正常。
所以,我有一个接受 byte[] 的方法,然后执行以下操作:
WWW w = new WWW("https://my-amazon-function-to-call");
yield return w;
if (!string.IsNullOrEmpty(w.error)) {
Debug.LogError(w.error);
}
else
{
var dict = Json.Deserialize(w.text) as Dictionary<string,object>;
string oneTimeUploadUrl = (string)dict["oneTimeUploadUrl"]; // …Run Code Online (Sandbox Code Playgroud) 我正在学习Elasticsearch,发现XPOST与XPUT“更新”或“替换”文档大致相同。它们都更改字段值。
curl -XPUT 'localhost:9200/customer/external/1?pretty' -d '
{
"name": "Jane Doe"
}'
curl -XPOST 'localhost:9200/customer/external/1/_update?pretty' -d '
{
"doc": { "name": "Jane Doe" }
}'
Run Code Online (Sandbox Code Playgroud)
因此他们都将名称字段更改为“ Jane Doe”。我想知道在上述情况下XPOST和之间有什么区别XPUT。
当通过 REST 更新资源时,应该在正文中只包含要更新的值,还是整个对象(当前值和要更新的值)?
如果用户对象看起来像这样
User (id, name, age, sex)
Run Code Online (Sandbox Code Playgroud)
我只想更新他的姓名和年龄,如果我的请求是这样的:
PUT /users/1
{"name":"john","age":18}
Run Code Online (Sandbox Code Playgroud)
或者像这样:
PUT /users/1
{"name":"john","age":18, "sex":"m"}
Run Code Online (Sandbox Code Playgroud)
在服务器端应该是什么样子?
@RequestMapping(value = "/{userId}", method = PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> updateUser(@PathVariable final int userId, @RequestBody User u){
//fetch user by ID
user.setName(u.getName())
user.setAge(u.getAge())
user.setSex(u.getSex()) //this will be empty?
return new ResponseEntity<String>(gson.toJson(user), HttpStatus.OK);
}
Run Code Online (Sandbox Code Playgroud)
或者我可以找出请求正文中未包含哪些变量并执行类似的操作
if(u.getName()!=null){
user.setName(u.getName())
}
if(u.getAge()!=null){
user.setAge(u.getAge())
}
if(u.getSex()!=null){
user.setSex(u.getSex())
}
Run Code Online (Sandbox Code Playgroud)
是否有正确/错误的方法来实现这一目标,还是只是做最简单的事情?
我使用 LDAP 用户设置了一个 keycloak 服务器,以便在我的应用程序上利用 SSO。我想通过 Keycloak API 更改应用程序中登录用户的密码。因此,将来我的 Angular 应用程序将能够向 keycloak API 发出请求来更改登录用户的密码。
因此,我尝试执行文档中指示的操作(方法 PUT,重置密码),但没有成功......我用邮递员进行了测试,我想知道我的令牌是否是要使用的令牌?问题是否来自其他地方?
我有这个网址:
PUT {url}/auth/admin/realms/{realm}/users/{id user}/reset-password/
我有这个标题:
Content-type application/json
我有这个身体:
{
"pass" : {
"type": "password",
"temporary": false,
"value": "my-new-password"
}
}
Run Code Online (Sandbox Code Playgroud)
如果我没有尝试快速更新令牌,我会收到 401 错误(这让我说问题可能不是来自令牌),而当我通过 postman oAuth 2.0 获得新令牌时,我会收到 403 或 400 错误
我有时会收到这样的消息:
Unrecognized field "pass" (class org.keycloak.representations.idm.CredentialRepresentation), not marked as ignorable
请帮我 !
你可以在这里看到我在邮递员中的授权,我不知道什么是“状态”
我不知道POST和PUT方法之间的确切区别。有些人在网上说当你更新记录时你必须使用PUT方法而不是POST,我不知道这是真的吗?
如果您的网站 URL 采用 POST 方法,则形成 Internet 1. www.example.com/user/{id}/update :- PUT 使用 2. www.example.com/user/update :- POST 使用 这是否正确?
我想它很简单,但我无法弄清楚如何做到这一点.我想使用AFNetworking库将文件上传到使用PUT请求到Web服务.这是我用来测试服务的curl命令
mac:~ user$ curl --verbose -T image.jpeg http://server.org:8001/social/test.jpg
* About to connect() to server.org port 8001 (#0)
* Trying 123.45.123.123...
* connected
* Connected to server.org (123.45.123.123) port 8001 (#0)
> PUT /social/test.jpg HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: server.org:8001
> Accept: */*
> Content-Length: 78341
> Expect: 100-continue
>
< HTTP/1.1 100 CONTINUE
< Server: cx1193719-b
< Content-Type: Text/Html
< Accept-Ranges: bytes
< Content-Length: 0
* We are completely uploaded and fine
< HTTP/1.1 200 …Run Code Online (Sandbox Code Playgroud) 在Max/MSP模块中,我有一个简单的Tcp客户端,可以将数据发送到服务器.我想用它来发送PUT请求到我的MIDI/OSC控制器(Eigenharp).它要求PUT请求打开其中一个灯.
现在,以下在cURL中有效:
curl http://localhost:1024/column/1/row/5 -X PUT --data green
Run Code Online (Sandbox Code Playgroud)
然而,
如何使用基本的TCP流完成类似的操作,而无需任何额外的库?
我面临与跨域PUT调用相关的问题,我已经允许来自服务器端的Access-Control-Allow-Origin仍然无法正常工作.
@PUT
@Path("/getresponse/{caller}")
@Produces({MediaType.APPLICATION_JSON})
public Response getResponseData(@PathParam("caller") String caller ,@QueryParam("ticket")String ticket ,@FormParam("formParam") String data){
ResponseBuilder resp;
System.out.println("name of caller is -> "+ caller);
System.out.println("query param ticket -> "+ ticket);
System.out.println("form param data->" + data);
Employee emp = new Employee();
emp.setAge(23);
emp.setName("data");
Gson gson = new Gson();
String responseJson = gson.toJson(emp);
resp=Response.ok(responseJson);//header("Access-Control-Allow-Origin", "*")
resp.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Methods", "GET, POST, PUT, OPTIONS");
return resp.build();
}
Run Code Online (Sandbox Code Playgroud)
每当我从jquery ajax方法调用它时,它表示 对预检请求的响应没有通过访问控制检查:请求的资源上没有'Access-Control-Allow-Origin'标头
我有相同的上述服务的副本,但有POST签名,当我调用该服务时,它调用服务没有任何问题邮政服务代码是
@POST
@Path("/getresponses/{caller}")
@Produces({MediaType.APPLICATION_JSON})
public Response getResponseData1(@PathParam("caller") String caller ,@QueryParam("ticket")String ticket …Run Code Online (Sandbox Code Playgroud)