-
-
Save msamoylov/5152ed92456fd557b540 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import SwiftHTTP | |
let serviceURL = "https://dpsdr.vlk.lt/PublicSearch.aspx" | |
let validResponse = "Apdraustas" | |
func checkInsuranceStatus(code: String) -> String { | |
var result = "UKNOWN" | |
var request = HTTPTask() | |
request.requestSerializer.headers["User-agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/8.0.3 Safari/600.3.18" | |
let params: Dictionary<String,AnyObject> = ["PersonCode": code] | |
request.POST(serviceURL, parameters: params, success: {(response: HTTPResponse) -> Void in | |
if response.responseObject != nil { | |
let data = response.responseObject as NSData | |
let str = NSString(data: data, encoding: NSUTF8StringEncoding) as String | |
println(str) | |
if str.rangeOfString(validResponse) != nil { | |
result = "OK" | |
} else { | |
result = "NOT OK" | |
} | |
} | |
}, failure: {(error: NSError, response: HTTPResponse?) -> Void in | |
result = "ERROR" | |
}) | |
println(result) | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment