private post method added to the iOS web client

This commit is contained in:
Vladimir Enchev
2014-03-28 14:32:02 +02:00
parent 1d46ada0df
commit b8314a3a4c
2 changed files with 34 additions and 1 deletions

View File

@ -69,4 +69,32 @@ export class Client {
}
}
}
private static post(url: string, postData: string, successCallback?: (result: any) => void, errorCallback?: (e: Error) => void) {
try {
var sessionConfig = Foundation.NSURLSessionConfiguration.defaultSessionConfiguration();
var queue = Foundation.NSOperationQueue.mainQueue();
var session = Foundation.NSURLSession.sessionWithConfigurationDelegateDelegateQueue(sessionConfig, null, queue);
var urlRequest = Foundation.NSMutableURLRequest.requestWithURL(Foundation.NSURL.URLWithString(url));
urlRequest.setHTTPMethod("POST");
urlRequest.setHTTPBody(Foundation.NSString.initWithString(postData).dataUsingEncoding(4));
var dataTask = session.dataTaskWithRequestCompletionHandler(urlRequest, function (data, response, error) {
if (error) {
if (errorCallback) {
errorCallback(new Error(error.localizedDescription()));
}
} else if (successCallback) {
successCallback(data);
}
});
dataTask.resume();
} catch (ex) {
if (errorCallback) {
errorCallback(ex);
}
}
}
}

View File

@ -60,7 +60,8 @@ declare module Foundation {
}
export class NSString {
static initWithDataEncoding(data: any, encoding: any) : any;
static initWithDataEncoding(data: any, encoding: any): any;
static initWithString(source: string): any;
}
export class NSURLSessionConfiguration {
@ -78,6 +79,10 @@ declare module Foundation {
export class NSURL {
static URLWithString(url : string): any;
}
export class NSMutableURLRequest {
static requestWithURL(url: any): any;
}
}
declare module QuartzCore {