iOS ASI--POST请求

柴丰
2023-12-01

发POST请求,需要用到专门的类:

#import "ASI/ASIFormDataRequest.h"

示例代码:

    // 设置url

    NSURL *url = [NSURL URLWithString:@"http://api.openweathermap.org/data/2.5/weather"];

    // 设置请求

    self.postRequest = [ASIFormDataRequest requestWithURL:url];

        [self.postRequest addPostValue:@35 forKey:@"lat"];

        [self.postRequest addPostValue:@139 forKey:@"lon"];

        // [self.postRequest setPostValue:@40 forKey:@"lat"];   setPostValue,会把35的值覆盖

        // [self.postRequest addPostValue:@41 forKey:@"lat"];    addPostValue,不会覆盖35的值,会产生1个新值41

    [self.postRequest setCompletionBlock:^{

        NSLog(@"请求完毕");

    }];    

    // 发起请求

    [self.request startAsynchronous];

转载于:https://www.cnblogs.com/oumygade/p/4249313.html

 类似资料: