0
我有一個龍捲風服務器,充當iPhone應用的REST接口。我想使用python程序對所述服務器執行一些查詢。在iOS端,我使用的是AFNetworking
庫。但我不知道python客戶端的模擬器是什麼。如何通過python3通過SSL進行BasicAuth REST查詢
我的ObjectiveC/AFNetworking代碼看起來是這樣的:
+ (HttpConnection*) current {
static HttpConnection* current = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
current = [[self alloc] initWithBaseURL: [NSURL URLWithString: BaseURL]];
current.securityPolicy.allowInvalidCertificates = YES;
current.responseSerializer = [AFJSONResponseSerializer serializer];
current.requestSerializer = [AFJSONRequestSerializer serializer];
});
[current.requestSerializer setAuthorizationHeaderFieldWithUsername: Username password: Password];
return current;
}
- (void)pull: (NSString*)resource fields: (NSArray*)fields then: (void(^)())block {
// NSLog(@"%@ pulling...", self);
NSString* uri = [NSString stringWithFormat: @"%@/%@", [self rootREST], self.serialID];
if (resource) {
uri = [NSString stringWithFormat: @"%@/%@", uri, resource];
}
[[HttpConnection current]
GET: uri
parameters: fields ? @{@"fields": fields} : nil
success:^(NSURLSessionDataTask* task, id responseObject){
[self performSelectorOnMainThread: @selector(fromDoc:) withObject:responseObject waitUntilDone:YES];
if (block) block();
}
failure:^(NSURLSessionDataTask* task, NSError* error){
NSLog(@"%@ pull error: %@ (uri=%@)", self, error, uri);
}
];
}
所以我要找的特點是:
- 初始化像
https://a.b.c:7895/
- 一個的BaseURL添加
resource/path
- 允許無效(自簽名)證書
- 設置
BasicAuth
頭 - 添加附加參數查詢
- 運行GET請求
難道我用urllib
做到這一切的?或者我需要使用不同的東西。我會喜歡我如何做到這一點的例子。
看起來好像還有一個debian軟件包。我會盡力的,謝謝。 – 2015-03-13 19:15:43