AFN incoming cookie

Source: Internet
Author: User
// 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.