标签: put

我应该使用 Post 或 Put 来编辑数据库中的人员,以及应该使用哪一个来添加新人员?

该方法现在如下所示:

POST person/personId/edit
https://api.example.com/*key*/person/*personId*/edit?FName=Blah
Run Code Online (Sandbox Code Playgroud)

我希望将 personId 中人员的名字更改为 Blah。

如果我需要添加一个人,我会说:

PUT person/create
https://api.example.com/*key*/person/create
Run Code Online (Sandbox Code Playgroud)

它会添加一个具有新 personId 的人。

database api rest post put

4
推荐指数
1
解决办法
8399
查看次数

Android HttpURLConnection PUT 到 Amazon AWS S3 403 错误

使用具有签名、到期日和访问密钥的预签名 URL 将文件上传到 Amazon S3,使用以下代码我可以使用普通的 java 代码上传文件,但在 Android 中相同的代码给了我 403 错误。使用 Amazon SDK 生成预签名 URL

我已阅读http://developer.android.com/reference/java/net/HttpURLConnection.htmlhttp://android-developers.blogspot.com/2011/09/androids-http-clients.html但无法阅读弄清楚我应该使用什么标头参数,我猜在 android 中它是在服务器拒绝的请求中设置标头

    HttpURLConnection connection=(HttpURLConnection) url.openConnection();
    connection.setDoOutput(true);
    connection.setRequestMethod("PUT"); 
    OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
    out.write("This text uploaded as object.");
    out.close();
    int responseCode = connection.getResponseCode();
Run Code Online (Sandbox Code Playgroud)

异常:403;签名不匹配:-o

有没有人遇到过这个问题?或者更多关于从android库在幕后添加哪些Header参数的细节?

java android put amazon-s3 httpurlconnection

4
推荐指数
1
解决办法
5344
查看次数

如何在Swift中创建GET,POST和PUT请求?

我可以在swift中与此代码段同步连接到服务器.

let URL: NSURL = NSURL(string: "http://someserver.com)!
let InfoJSON: NSData? = NSData(contentsOfURL: URL)
let JsonInfo: NSString = NSString(data:InfoJSON!, encoding: NSUTF8StringEncoding)!
let GameListAttributions: NSArray = NSJSONSerialization.JSONObjectWithData(InfoJSON!, options: .allZeros, error: nil)! as NSArray
Run Code Online (Sandbox Code Playgroud)

这仅适用于一次接收所有信息,但我如何使用Swift使用GET,POST和PUT.无论我搜索多少,我都找不到关于如何执行这些的好教程或示例.

post get put ios swift

4
推荐指数
1
解决办法
1万
查看次数

PUT 请求不起作用,Flask-RESTful,SQLAlchemy

我相信问题在于提交对数据库的更改(倒数第三行:)db.session.commit()。以一个用户为例:username="Foo", email="Bar@yahoo.com"。如果在 PUT 请求正文中我放了 {"email":"changed@gmail.com"},则在赋值后打印 'user.email' 表明该值实际上已更改。然而之后,在查询数据库时,电子邮件保持不变。无论如何,我真的很难弄清楚我错过了什么,所以感谢任何帮助!

class UserAPI(Resource):
    def __init__(self):
        self.parser = reqparse.RequestParser()
        self.parser.add_argument('username', type=str, location='json')
        self.parser.add_argument('email', type=str, location='json')
        self.parser.add_argument('password', type=str, location='json')
        super(UserAPI, self).__init__()

    def put(self, id): 
        # Not working
        user = User.query.filter_by(id=id).first()
        if user is not None:
            args = self.parser.parse_args()
            for key, value in args.items():
                if args[key] is not None:
                    user.key = value
            db.session.commit()
            return {"user": marshal(user,user_field) }
        return {"error": "User not found"}, 404
Run Code Online (Sandbox Code Playgroud)

sqlalchemy put flask flask-sqlalchemy flask-restful

4
推荐指数
1
解决办法
2476
查看次数

HTTP规范:没有数据传输的PUT,因为服务器已知数据哈希

HTTP/WebDav规范是否允许此客户端 - 服务器对话框?

  1. client:我想将数据PUT到/user1/foo.mkv,它有这个哈希值:HASH
  2. 服务器:好的,PUT成功了,你不需要发送数据,因为我已经知道了这个哈希值的数据.

注意:此PUT是初始上传.这不是更新.

如果可以,则可以实现更快的文件同步.

使用案例:WebDAV服务器为每个用户托管一个目录.最喜欢的视频foo.mkv由多个用户上传.在此示例中,收藏的视频已存储在此位置:/user2/myfoo.mkv.第二次和以后的上传不需要发送任何数据,因为服务器已经知道内容.这会减少很多网络负载.

前提条件:

  • 客户端和服务器需要事先就哈希算法达成一致.
  • 服务器需要存储已知文件的哈希值.

在自定义客户端和服务器中实现它非常容易.但这不是我想要的.

我的问题:是否有允许这样的对话的RFC或其他标准?

如果还没有标准,那么如何实现这个梦想呢?

安全考虑

通过上面的对话框,它将能够访问已知哈希的内容.恶意客户端的示例知道存在哈希值为的文件1234567....他可以执行上述两个步骤,之后客户端可以使用GET下载数据.

解决此问题的方法是扩展对话框:

  1. 客户端:我想要PUT具有此哈希值的数据:HASH
  2. 服务器:好的,PUT会成功,但为了确保你有数据,请把字节N发给我直到M.我需要这个以确保你有哈希值数据.
  3. 客户端:字节数N到数据的M是 abcde...
  4. 服务器:好的,你的字节匹配我的.我信任你.上传成功,您不再需要发送数据.

怎么做到这一点?

由于似乎还没有规范,问题的这一部分仍然存在:

如何实现梦想成真?

hash webdav put rfc deduplication

4
推荐指数
1
解决办法
506
查看次数

CURLOPT_PUT 与 CURLOPT_POSTFIELDS

当我通过 curl 将 PUT 请求 API 发送到 REST 时,我发现了奇怪的行为。如果设置参数curl_setopt($curl, CURLOPT_PUT, true),则查询,其中 CURLOPT_POSTFIELDS 不为空,则查询执行持续 1.5 分钟(好像它取决于某个超时)。如果使用参数curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT")发送相同的请求,那么查询执行将持续大约 1 秒,这是应该的。有人可以解释这些参数之间的根本区别吗?

示例代码:

$data = http_build_query(array("enable"=> 1));

if( $curl = curl_init() ) {
    curl_setopt($curl, CURLOPT_URL, BASE_URL .'users/2');
    curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);    
    curl_setopt($curl, CURLOPT_PUT, true); // execution time 1.5 min
    //curl_setopt ($ curl, CURLOPT_CUSTOMREQUEST, "PUT"); - execution time 1 sec
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    $out = json_decode(curl_exec($curl));
    curl_close($curl);      
}
Run Code Online (Sandbox Code Playgroud)

php api curl put

4
推荐指数
1
解决办法
8118
查看次数

为什么我的http.put请求不起作用?均值堆栈

我正在使用API​​构建应用程序,到目前为止,所有http请求(get,post)都工作正常。现在,我向我的服务中添加了一个put请求,由于某种原因,它不起作用。

这是我所谓的服务功能:

export class ChatStartComponent implements OnInit {

  @ViewChild('d1') d1:ElementRef;

  socket = io.connect('http://localhost:3000');

  constructor(private usersService: UsersService) {
    this.currentUser = JSON.parse(localStorage.getItem('currentUser'));
    this.currentUserName = this.currentUser.name;
    this.usersService.updateUser(this.currentUser._id); <--update Users does not
    /*this.usersService.getUsers()  <-- getUsers does work
      .subscribe(users => {
        this.users.push(users);
      });*/
  }
Run Code Online (Sandbox Code Playgroud)

参数currentUser._id确实存在,我可以在此时控制台对其进行登录。

这是服务功能:

  addUser(newUser) {
    var headers = new Headers();
    headers.append('Content-Type', 'application/json');
    return this.http.post('http://localhost:3000/api/user', JSON.stringify(newUser), {headers: headers});
  }

  updateUser(_id: string) {
    var set = {
      loggedIn: true
    };
    console.log(set, _id);
    return this.http.put('http://localhost:3000/api/update/' + _id, JSON.stringify(set))
      .map(res => res.json());
  }
Run Code Online (Sandbox Code Playgroud)

上面的http.post调用工作正常,但放置的updateUser根本不工作。console.log被触发了,我确实记录了ID,但http.put调用不起作用。

这是服务器端代码:

router.put('/update/:id', …
Run Code Online (Sandbox Code Playgroud)

api put mean-stack angular

4
推荐指数
2
解决办法
3230
查看次数

Laravel 中何时使用 PATCH 和 PUT 方法?

我不知道 PATCH 和 PUT 方法之间的确切区别。谁能告诉我什么时候应该使用这种方法并举出适当的例子。

patch put laravel

4
推荐指数
1
解决办法
9026
查看次数

除表单提交之外的HTTP请求的MIME类型

对于不是由HTML表单发送的请求,HTTP是否将请求的Content-Type限制为application/x-www-form-urlencoded以用于非文件上载,或者是MIME类型"right"/标准/语义在任何其他方面有意义办法?

例如,PHP会自动将内容解析为$ _POST,这似乎表明服务器需要x-www-form-urlencoded.另一方面,我可以使用Ajax在HTTP请求内容中发送JSON对象,并将Content-Type设置为application/json.至少一些服务器技术(例如WSGI)不会尝试解析它,而是以原始形式向脚本提供它.

我应该在RESTful API中的POST和PUT请求中使用什么MIME类型来确保符合HTTP的所有服务器实现?我忽略了SOAP和JSON-RPC等技术,因为它们通过HTTP隧道传输协议而不是按预期使用HTTP.

post http put http-headers http-request

3
推荐指数
1
解决办法
7441
查看次数

不能用烧瓶的PUT方法

我写了这个简单的程序:

@app.route('/puttest/', methods=['GET', 'PUT'])
def upload_file():
    if request.method == 'PUT':
        return 'Hello, {}!'.format(request.form['name'])
    else:
        return '''
            <title>Does it work ?</title>
            <h1>PUT test</h1>
            <form action=http://localhost:8887/puttest/ method=put>
                <input type=text name=name>
                <input type=submit value=try>
            </form>

        '''

if __name__ == '__main__':
    app.run('0.0.0.0', 8887)
Run Code Online (Sandbox Code Playgroud)

它适用于GET方法,但它无法使用PUT.尝试发送put消息,我可以在浏览器中看到此错误:

Method Not Allowed

The method is not allowed for the requested URL.
Run Code Online (Sandbox Code Playgroud)

put方法发生了什么?

如果我在程序中的任何地方改变put方法,它将工作正常post.

python put flask

3
推荐指数
1
解决办法
2944
查看次数