zoukankan      html  css  js  c++  java
  • iOS 的 PATCH请求

    我们在iOS 开发中 经常用到的get和post请求,除此之外还有好几种请求方式!

    http协议申明了客户端与服务端交互的方式,即请求方式:
    get、post、put、delete
    这四种方式可以对网络资源(url描述的内容)进行:查、改、增、删,其实post是添加一条数据!  

    在修改某一个表中的某一个字段的时候  使用patch会更加灵活,简便! 我们只需要传 需要修改的  字段名 和 修改的 值,然后通过patch方式去修改!  

     NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];

        [request setHTTPMethod:@"PATCH"];

        [request setHTTPBody:[jsonStr dataUsingEncoding:NSUTF8StringEncoding]];

        [request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

        

        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

            NSDictionary *dictionary = [data objectFromJSONData];

            NSLog(@"---- -- - -- - - -- - -- - - ----==-- - == p= p; = %@",dictionary);

            success(dictionary);

        }];

     相信这段代码大家都能看懂 !  

    参数  jsonStr 需要这种形式   jsonStr = @"{key:value}";

  • 相关阅读:
    LeetCode First Bad Version (二分查找)
    LeetCode Permutations II (全排列)
    LeetCode Permutations (全排列)
    LeetCode Minimum Path Sum (简单DP)
    LeetCode Binary Tree Postorder Traversal(数据结构)
    LeetCode Sort Colors (技巧)
    邹忌
    参数传递
    父子窗体返回值与互操作
    其他数据库连接
  • 原文地址:https://www.cnblogs.com/Seeulater/p/4223966.html
Copyright © 2011-2022 走看看