我刚刚开始使用JSONModel。JSONHTTPClient 可以处理支持“GET”和“POST”方法的异步网络请求。有没有办法使用 JSONHTTPClient 发出“PUT”或“DELETE”请求?
问问题
810 次
2 回答
0
在这里查看文档
http://jsonmodel.com/docs/Classes/JSONHTTPClient.html#//api/name/requestHeaders
看来你做不到。您将不得不使用另一种方法来执行此操作。可能是另一个框架或 NSURLSessions 或在 JSONHTTPClient 类上编写您自己的类别。
于 2015-03-18T11:02:17.583 回答
0
无论如何,我通过向 JSONHTTPClient 添加新方法来提供最愚蠢的解决方案。
+(void)putJSONFromURLWithString:(NSString)urlString params:(NSDictionary)params completion:(JSONObjectBlock)completeBlock;
+(void)putJSONFromURLWithString:(NSString)urlString bodyString:(NSString)bodyString completion:(JSONObjectBlock)completeBlock;
+(void)putJSONFromURLWithString:(NSString)urlString bodyData:(NSData)bodyData completion:(JSONObjectBlock)completeBlock;
我还添加了一个新的 const NSString 来支持“PUT”
NSString* const kHTTPMethodPUT = @"PUT";
+(void)putJSONFromURLWithString:(NSString*)urlString params:(NSDictionary*)params completion:(JSONObjectBlock)completeBlock
{
[self JSONFromURLWithString:urlString method:kHTTPMethodPUT
params:params
orBodyString:nil completion:^(id json, JSONModelError* e) {
if (completeBlock) completeBlock(json, e);
}];
}
+(void)putJSONFromURLWithString:(NSString*)urlString bodyString:(NSString*)bodyString completion:(JSONObjectBlock)completeBlock
{
[self JSONFromURLWithString:urlString method:kHTTPMethodPUT
params:nil
orBodyString:bodyString completion:^(id json, JSONModelError* e) {
if (completeBlock) completeBlock(json, e);
}];
}
+(void)putJSONFromURLWithString:(NSString*)urlString bodyData:(NSData*)bodyData completion:(JSONObjectBlock)completeBlock
{
[self JSONFromURLWithString:urlString method:kHTTPMethodPUT
params:nil
orBodyString:[[NSString alloc] initWithData:bodyData encoding:defaultTextEncoding]
completion:^(id json, JSONModelError* e) {
if (completeBlock) completeBlock(json, e);
}];
}
我还在GitHub 上创建了一个问题。希望得到那里的回应。
于 2015-03-18T11:04:11.603 回答