相关疑难解决方法(0)

我什么时候应该使用GET或POST方法?他们之间有什么区别?

使用GETPOST方法有什么区别?哪一个更安全?他们每个人的(dis)优势是什么?

(类似问题)

forms post get http http-method

236
推荐指数
11
解决办法
17万
查看次数

使用POST的Flask示例

假设以下路由访问xml文件以使用给定的xpath(?key =)替换特定标记的文本:

@app.route('/resource', methods = ['POST'])
def update_text():
    # CODE
Run Code Online (Sandbox Code Playgroud)

然后,我会像这样使用cURL:

curl -X POST http://ip:5000/resource?key=listOfUsers/user1 -d "John"
Run Code Online (Sandbox Code Playgroud)

xpath expreesion listOfUsers/user1应该访问标记<user1>以将其当前文本更改为"John".

我不知道如何实现这一点,因为我刚刚开始学习Flask和REST,我找不到任何关于这个具体案例的好例子.此外,我想使用lxml来操作xml文件,因为我已经知道了.

有人可以帮助并提供一个指导我的例子吗?

python rest lxml flask

42
推荐指数
2
解决办法
11万
查看次数

request.method =="POST"在Django中意味着什么?

我在我的观点中使用这个东西很多,但我想知道究竟是什么意思?当我们写request.method =="GET"或"POST"时会发生什么

django post request

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

HTTP post:url参数和表单数据

当我通过Web表单执行http POST请求时,URL中指定的参数与服务器端传递的参数之间是否存在任何差异(实际上或理论上)?

我可以使用url参数进行整个POST,并期望与表单输入相同的结果吗?

喜欢:

  <form action="/?id=2" method="post">
      <input type="text" name="name" value="John"/>
      <input type="submit" value="submit"/>
  </form>
Run Code Online (Sandbox Code Playgroud)

要么:

  <form action="/?id=2&name=John" method="post">
      <input type="submit" value="submit"/>
  </form>
Run Code Online (Sandbox Code Playgroud)

谢谢.

html parameters post http

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

如何使用JSON参数cURL发布?

我不确定这是否可行,但我正在尝试卷曲帖子,但是以json为参数,如下:

curl -X POST 'https://myserver/action?params={"field1":"something","whatever":10,"description":"body","id":"random","__oh__":{"session":"12345678jhgfdrtyui"}}'
Run Code Online (Sandbox Code Playgroud)

但是,我不断收到一些错误curl: (3) [globbing] nested braces not supported at posX.

我该怎么做呢?

post json curl

13
推荐指数
2
解决办法
2万
查看次数

Spring Data JPA:如何优雅地更新模型?

  1. 我的模型是这样的:

    @Entity
    @Table(name = "user")
    public class User {
    
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long id;
    
        @Column(name="email")
        private String email;
    
        @Column(name = "weblink")
        private String webLink;
    
        //getter & setter
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 我们通过http请求收集表单或移动数据,springmvc会将这些数据发送给像用户这样的模型.

    例如,我有这样的请求:

    http://localhost:8080/update?id=1919&email=xx@google.com

  3. 在控制器中,请求URL及其参数将自动转换为User对象.

    @RequestMapping(method = RequestMethod.GET, value = "/update0")
    public User update(@ModelAttribute("User") User user){
    
        System.out.println(user.getId());
        System.out.println(user.getEmail());
        System.out.println(user.getWebLink());
    
        return userRepository.save(test);
    }
    
    Run Code Online (Sandbox Code Playgroud)
  4. 如果我在mysql中有一个id为1919的记录,并且列(id,email,weblik)都有值.

    如您所见,通过Web或移动设备传递的用户对象具有两个属性

    http://localhost:8080/update?id=1919&email=xx@google.com

    id和电子邮件有值,而weblink没有.

    因此,如果我执行save方法,列电子邮件将更新为xx@google.com,weblik字段也将更新为NULL,但我不想更新此字段,我只想更新电子邮件字段.

  5. 我有两种方法来解决这个问题,但所有这些方法都不优雅.

    5.1首先加载用户对象并更新

    User userExist = userRepository.findOne(user.getId());
    userExist.setEmail(user.getEmail());
    
    //or using 
    //BeanUtil.copyProprty(formDto,modle)
    
    userRepository.save();
    
    Run Code Online (Sandbox Code Playgroud)

    5.2使用@DynamicUpdate,但不起作用.

    是否有其他方法来更新用户模型,不做一些额外的工作.

    提前致谢.

spring spring-mvc spring-data spring-data-jpa spring-boot

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

$_POST、$_GET 和 $_REQUEST 之间有什么区别?

我对 PHP 中的这些超级全局变量 ( $_POST, $_GET, 和$_REQUEST)感到有些困惑。在什么情况下我需要在 PHP 中使用这些变量,这三个代表的主要区别是什么?

php global-variables

10
推荐指数
3
解决办法
2万
查看次数

如何从AFNETWORKING POST获取参数

如何从Swift获取参数值,文件上传已经有效,我已经尝试了$ _GET ["familyId"],但它没有用?

迅速:

    let manager = AFHTTPRequestOperationManager()
    let url = "http://localhost/test/upload.php"
    var fileURL = NSURL.fileURLWithPath(NSBundle.mainBundle().pathForResource("test_1", ofType: "mov")!)
    var params = [
        "familyId":locationd,
        "contentBody" : "Some body content for the test application",
        "name" : "the name/title",
        "typeOfContent":"photo"
    ]

    manager.POST( url, parameters: params,
        constructingBodyWithBlock: { (data: AFMultipartFormData!) in
            println("")
            var res = data.appendPartWithFileURL(fileURL, name: "fileToUpload", error: nil)
            println("was file added properly to the body? \(res)")
        },
        success: { (operation: AFHTTPRequestOperation!, responseObject: AnyObject!) in
            println("Yes thies was a success")
        },
        failure: { …
Run Code Online (Sandbox Code Playgroud)

php afnetworking swift

8
推荐指数
1
解决办法
477
查看次数

将图像上传到服务器详细说明初学者

我正在努力将图像上传到服务器,因为有很多关于通过AFNetworking和NSURLSession上传图像的问题以及其他上传所有我想问的方法是我没有找到解释关于事情是如何工作以及在幕后发生了什么的整个概念我在搜索youtube时也可以在Swift中找到所有的东西并且完全不相信我的结果我发现这个答案对我来说很熟悉



    //Init the NSURLSession with a configuration
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]];

//Create an URLRequest
NSURL *url = [NSURL URLWithString:@"yourURL"];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];

//Create POST Params and add it to HTTPBody
NSString *params = @"api_key=APIKEY&email=example@example.com&password=password";
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];

//Create task
NSURLSessionDataTask *dataTask = [defaultSession dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
    //Handle your response here
}];

[dataTask resume];
Run Code Online (Sandbox Code Playgroud)

关于这个话题最受欢迎的答案是用户XJones: -

Here's code …
Run Code Online (Sandbox Code Playgroud)

networking xcode objective-c ios nsurlsession

8
推荐指数
1
解决办法
764
查看次数

数据和请求中的参数有什么区别?

我正在使用python requests模块,我之前发送过这样的参数:

requests.post(url=url, params=params)
Run Code Online (Sandbox Code Playgroud)

但是今天,我发现我像这样发送数据,但失败了,我改成这样:

requests.post(url=url, data=params)
Run Code Online (Sandbox Code Playgroud)

那没关系,data和和有params什么区别?

我观察到请求有一个标头X-Requested-With:XMLHttpRequest,是因为这个吗?

python params python-requests

5
推荐指数
2
解决办法
3055
查看次数