Reputation: 919
I am working on Objective-C language and I need to fire curl from Objective-C.
My curl is:
curl https://api.start.payfort.com/tokens/ \
-u test_open_k_91ffe6d8f9efe14fcc91: \
-d "number=4242424242424242" \
-d "exp_month=11" \
-d "exp_year=2016" \
-d "cvc=123" \
-d "name=sapana"
Please help me how to convert this url in Objective-C and fire url.
I tried some other way but they return response like:
{
error = {
code = "not_found";
extras = {
"request_id" = "f8e70bf6-9391-49b0-9403-06cc9485c021";
time = "2016-01-27T11:10:31Z";
};
message = "Not Found";
type = processing;
};
}
Upvotes: 0
Views: 250
Reputation: 343
It's work for me. But swift
func cardSendToPayFort(number:String, exp_month:String, exp_year:String, cvc:String, name:String, completion: ((success: Bool, json: NSDictionary?) -> Void))
{
let username = "test_open_k_91ffe6d8f9efe14fcc91"
let password = ""
let loginString = NSString(format: "%@:%@", username, password)
let loginData: NSData = loginString.dataUsingEncoding(NSUTF8StringEncoding)!
let base64LoginString = loginData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength)
let orderURL = NSURL(string: "https://api.start.payfort.com/tokens/")
let request = NSMutableURLRequest(URL: orderURL!)
request.setValue("Basic \(base64LoginString)", forHTTPHeaderField: "Authorization")
let postString = "number=\(number)&exp_month=\(exp_month)&exp_year=\(exp_year)&cvc=\(cvc)&name=\(name)"
//let postString = "number=4242424242424242&exp_month=11&exp_year=2016&cvc=123&name=sapana"
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
request.HTTPMethod = "POST"
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithRequest(request) { (data, response, error) -> Void in
if let httpStatus = response as? NSHTTPURLResponse where httpStatus.statusCode != 201 {
print("statusCode should be 201, but is \(httpStatus.statusCode)")
print("response = \(response)")
dispatch_async(dispatch_get_main_queue()){
completion(success: false, json: nil)
}
} else {
let responseString = String(data: data!, encoding: NSUTF8StringEncoding)
let jsonData = responseString?.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
let json = try! NSJSONSerialization.JSONObjectWithData(jsonData!, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
dispatch_async(dispatch_get_main_queue()){
completion(success: true, json: json)
}
}
}
task.resume()
}
Upvotes: 1