【发布时间】:2014-11-05 03:16:01
【问题描述】:
Foundation 是否有 NSString 常量用于支持的 HTTPMethod 值(例如,用于 GET、POST 等)?
搜索了 NSURLRequest 文档,但找不到任何东西。
【问题讨论】:
标签: ios macos cocoa nsurlrequest
Foundation 是否有 NSString 常量用于支持的 HTTPMethod 值(例如,用于 GET、POST 等)?
搜索了 NSURLRequest 文档,但找不到任何东西。
【问题讨论】:
标签: ios macos cocoa nsurlrequest
据我所知,NSURLRequest 没有任何 HTTP 方法类型的常量。但是,您可以定义自己的并在其他地方使用它们。像这样的:
//Somewhere
#define setPOST(request) [request setHTTPMethod:@"GET"]
//...later in code
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
setPOST(request);
我也强烈推荐使用AFNetworking。使用该库,您可以轻松地执行以下操作:
[connectionMgr POST:url parameters:submitDict success:nil failure:nil]; //Obviously bare-bones, you'd need to fill in the parameters and blocks
【讨论】: