0
我有一個iphone應用程序,我試圖使用HTTPRiot做一些API調用Web應用程序。問題是我看不到任何HTTPRiot委託方法正在被調用。我已經登錄了所有的委託方法,並且還在查看Web服務器日誌。我看到網址正在被擊中。問題得到HTTPRiot工作
//API.h
#import <Foundation/Foundation.h>
#include <HTTPRiot/HTTPRiot.h>
@interface API : HRRestModel {
}
+(void)runTest;
@end
//API.m
#import "API.h"
@implementation API
+ (void)initialize {
NSLog(@"api initialize");
[self setDelegate:self];
[self setBaseURL:[NSURL URLWithString:@"http://localhost:3000/api"]];
[self setBasicAuthWithUsername:@"demo" password:@"123456"];
NSDictionary *params = [NSDictionary dictionaryWithObject:@"1234567" forKey:@"api_key"];
[self setDefaultParams:params];
}//end initialize
+(void)runTest {
NSLog(@"api run test");
// Would send a request to http://localhost:1234/api/people/1?api_key=1234567
[self getPath:@"/save_diet" withOptions:nil object:nil];
}
+(void)restConnection:(NSURLConnection *)connection didReturnResource:(id)resource object:(id)object {
NSLog(@"didReturnResource");
}
+(void)restConnection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response object:(id)object {
NSLog(@"didReceiveResponse");
}
+(void)restConnection:(NSURLConnection *)connection didReceiveParseError:(NSError *)error responseBody:(NSString *)body object:(id)object {
NSLog(@"didReceiveParseError");
}
+(void)restConnection:(NSURLConnection *)connection didReceiveError:(NSError *)error response:(NSHTTPURLResponse *)response object:(id)object {
NSLog(@"didReceiveError");
}
+(void)restConnection:(NSURLConnection *)connection didFailWithError:(NSError *)error object:(id)object {
NSLog(@"didFailWithError");
}
@end
//test code
[API runTest];
//log output
代碼(+初始化和其他)直接從HTTPRiot文檔中取得,我更改了代碼以使用類方法而不是實例方法用於委託方法,並且我得到了didReceiveResponse:來調用,但didReturnResource :沒有。 – bwizzy 2009-11-25 02:41:32