// Pass the cookie when sending the POST request
+ (Void) requestcookiewithpath :( nsstring *) path
Params :( nsdictionary *) Params
Method :( nsstring *) Method
Success :( httpsuccessblock) Success {
// Create a POST request
// Create an afhttpclient object
Afhttpclient * client = [afhttpclient clientwithbaseurl: [nsurl urlwithstring: kbaseurl];
Nsmutableurlrequest * post = [client requestwithmethod: Method path: path parameters: Params];
Nsdata * cookiesdata = [[nsuserdefaults standarduserdefaults] objectforkey: @ "Set-cookie"];
If ([cookiesdata length]) {
Nsarray * cookies = [nskeyedunarchiver unarchiveobjectwithdata: cookiesdata];
Nshttpcookie * cookie;
For (cookie in cookies ){
[[Nshttpcookiestorage sharedhttpcookiestorage] setcookie: cookie];
}
}
// Create an afjsonrequestoperation object
Nsoperation * operation = [afjsonrequestoperation jsonrequestoperationwithrequest: Post success: ^ (nsurlrequest * request, nshttpurlresponse * response, Id JSON ){
Success (JSON );
} Failure: ^ (nsurlrequest * request, nshttpurlresponse * response, nserror * error, Id JSON ){
Nslog (@ "error = % @", error );
// Request timeout prompt
Nsstring * errorstr = [[nsstring alloc] initwithformat: @ "% @", error];
Nsstring * theerror = @ "the request timed out .";
If ([errorstr rangeofstring: theerror]. length> 0 ){
Uialertview * Alert = [[uialertview alloc] initwithtitle: @ "prompt" message: @ "request timeout" delegate: Self cancelbuttontitle: @ "OK" otherbuttontitles: Nil];
[Alert show];
}
}];
// Start the request
[Operation start];
}
AFN incoming cookie