IPhoneDeveloping applicationsASIFormDataRequestPOST OperationArchitectureDesign is the content of this article.ASIFormDataRequestPOST OperationArchitectureDesign, methods defined by yourself. The content is mainly implemented based on code. Let's look at the detailed code.
- // Enable the iphone network switch
- [UIApplication sharedApplication]. networkActivityIndicatorVisible = YES;
- ASIFormDataRequest * request = [[ASIFormDataRequest alloc] initWithURL: [NSURLURLWithString: host];
- // Timeout
- Request. timeOutSeconds = 30;
- // Define the Asynchronous Method
- [Request setDelegate: self];
- [Request setDidFailSelector: @ selector (requestDidFailed :)];
- [Request setDidFinishSelector: @ selector (requestDidSuccess :)];
-
- // User-defined data dictionary type (optional)
- Request. userInfo = [NSDictionary dictionaryWithObject: method forKey: @ "Method"];
- // Post Data
- [Request appendPostData: [body dataUsingEncoding: NSUTF8StringEncoding];
- // Start execution
- [Request startAsynchronous];
- // Execution successful
- -(Void) requestDidSuccess :( ASIFormDataRequest *) request
- {
- // Obtain the header file
- NSDictionary * headers = [request responseHeaders];
- // Obtain the http protocol Execution Code
- NSLog (@ "Code: % d", [request responseStatusCode]);
- If ([delegaterespondsToSelector: @ selector (OARequestSuccessed: withResponse: WithData: withHeaders :)])
- {
- // Select the operating architecture to be delegated)
- [Delegate OARequestSuccessed: method withResponse: [request responseString] WithData: [request responseData] withHeaders: headers];
- }
- // Clear
- If (request)
- {
- [Request release];
- }
- // Disable the network
- [UIApplication sharedApplication]. networkActivityIndicatorVisible = NO;
- }
- // Execution failed
- -(Void) requestDidFailed :( ASIFormDataRequest *) request {
-
- // Obtain the User-Defined content
-
- NSString * method = [request. userInfo objectForKey: @ "Method"];
- // Get Error Data
- NSError * error = [request error];
- If ([delegate respondsToSelector: @ selector (OARequestFailed: withError :)])
- {
- // Execute the delegate to transfer the wrong data to other methods. The architecture design is optional)
- [Delegate OARequestFailed: method withError: error];
- }
- If (request)
- {
- [Request release];
- }
- [UIApplication sharedApplication]. networkActivityIndicatorVisible = NO;
- }
-
- // Function for successful execution
-
- -(Void) OARequestSuccessed :( NSString *) method withResponse :( NSString *) response WithData :( NSData *) data withHeaders :( NSDictionary *) headers
- {
- NSString * responseStr = [[NSString alloc] initWithData: dataencoding: NSUTF8StringEncoding] autorelease];
- // The service returns post Data
- NSLog (@ "response: \ n % @", responseStr );
- }
-
- // Execution failure Function
- -(Void) OARequestFailed :( NSString *) method withError :( NSError *) error
- {
- NSLog (@ "Error: % @", error );
- UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "error" message: @ "network connection failed. Please try again later ."
- Delegate: nil cancelButtonTitle: @ "good" otherButtonTitles: nil];
- [Alert show];
- [Alert release];
- }
Summary:IPhoneDeveloping applicationsASIFormDataRequestPOST OperationArchitectureThe content of the design has been introduced. I hope this article will help you!