Skip to content

Instantly share code, notes, and snippets.

View hardez's full-sized avatar

Marco hardez

  • Niedersachsen, Germany
View GitHub Profile
func postArrayToUrl(urlToRequest: String, params: NSMutableDictionary) -> AnyObject {
var url: NSURL = NSURL(string: urlToRequest)!
var request = NSMutableURLRequest(URL: url)
var response: NSURLResponse?
var error: AutoreleasingUnsafeMutablePointer <NSError?> = nil
request.HTTPMethod = "POST"
request.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: nil, error: error)
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
var test = NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error: error)
var resp:AnyObject = NSJSONSerialization.JSONObjectWithData(test!, options: NSJSONReadingOptions.MutableContainers, error: error)! as AnyObject
@hardez
hardez / gist:985ce910f82f151b01e2
Created January 4, 2015 15:53
NSURLConnectionDelegate
func connection(connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: NSURLProtectionSpace?) -> Bool
{
return protectionSpace?.authenticationMethod == NSURLAuthenticationMethodServerTrust
}
func connection(connection: NSURLConnection, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge?)
{
if challenge?.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust
{
if challenge?.protectionSpace.host == "www.myhost.com"