Blog. csdn. netzengraoliarticledetails12918369 in the blog text iOS use ASIHttpRequestJson for login verification with the server segment script. I am sorry for not making it clear how it actually interacts; after all, I only use php for these days .. First, let's take a look at the php client I just wrote: [php] viewp
Http://blog.csdn.net/zengraoli/article/details/12918369 in the blog iOS use ASIHttpRequestJson and server segment script login verification, not carefully said clearly, in the end is how to interact, I am very sorry; after all, I only use php for these days .. First, let's look at a php client I just wrote: [php] view p
Http://blog.csdn.net/zengraoli/article/details/12918369
In the blog
IOS uses ASIHttpRequest + Json to perform login verification with the server segment script. I am sorry for not carefully explaining how the script interacts. After all, I only use php for the past few days ..
First, let's look at a php client I just wrote:
[Php]View plaincopyprint?
-
-
- $ Arr;
- Function traverse ($ path = '.')
- {
- $ Current_dir = opendir ($ path); // opendir () returns a directory handle. If it fails, false is returned.
- $ Directory_arr;
- $ File_arr;
-
- $ Directory_index = 1;
- $ File_index = 1;
-
- Global $ arr;
- $ Arr_index = 0;
-
- While ($ file = readdir ($ current_dir ))! = False)
- {// Readdir () returns an entry in the Open Directory handle.
- $ Sub_dir = $ path. DIRECTORY_SEPARATOR. $ file; // build the subdirectory path
- If ($ file = '.' | $ file = '..')
- {
- Continue;
- }
- Else if (is_dir ($ sub_dir ))
- {// Perform recursion for directories
- // Echo 'Directory '. $ file .':
';
- $ String = "Directory ";
- $ String. = $ directory_index;
- $ Directory_arr [$ string] = $ file;
- $ Directory_index ++;
- Traverse ($ sub_dir );
- // Print_r ($ directory_arr );
- }
- Else
- {// If it is a file, direct output
- // Echo 'file in Directory '. $ path.': '. $ File .'
';
- $ File_arr [$ file_index] = $ path. '\'. $ file .'
';
- $ File_index ++;
- }
- };
-
- $ Arr ["dir_count"] = count ($ directory_arr );
- // Print_r ($ file_arr );
- // Print_r (count ($ file_arr ));
- // Echo'
';
- // Echo "================================ ";
- // Echo'
';
-
- // One of them is a titleworkflow first, and the other half is a. txt.
- $ Arr [$ path] = (count ($ file_arr)-1)/2;
- }
-
- Traverse ('images ');
- // Print_r ($ arr );
-
- // Print_r (json_encode ($ arr ));
-
- $ ResultJson = json_encode ($ arr );
- Echo $ resultJson;
- ?>
The following page is displayed after the php script is directly run on the server:
This is a demo of getting the current webrootdirectory, the number of directories in the imagesfolder, and the number of .jpg files.
Here is the content of day1:
On the corresponding iOS end, write as follows:
[Cpp]View plaincopyprint?
- //
- // ViewController. m
- // Demo
- //
- // Created by zengraoli on 13-10-20.
- // Copyright (c) 2013 zeng. All rights reserved.
- //
-
- # Import "ViewController. h"
- # Import "UIView + Additon. h"
-
-
- @ Interface ViewController ()
-
- @ End
-
- @ Implementation ViewController
-
- -(Void) viewDidLoad
- {
- [Super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
-
- [Self getResourcesCount];
- }
-
- -(Void) getResourcesCount
- {
- NSString * baseurl = @ "get_resources_count.php ";
-
- NSURL * url = [NSURL URLWithString: [NSString stringWithFormat: @ "% @", host_url, baseurl];
- [Self setRequest: [ASIHTTPRequest requestWithURL: url];
- [_ Request addRequestHeader: @ "User-Agent" value: @ "ASIHTTPRequest"];
- [_ Request startSynchronous];
-
- // Display the network request information on the status bar
- [ASIHTTPRequest setShouldUpdateNetworkActivityIndicator: YES];
-
- If (_ request)
- {
- If ([_ request error])
- {
- NSLog (@ "error ");
- }
- Else if ([_ request responseString])
- {
- NSString * result = [_ request responseString];
- // NSLog (@ "% @", result );
- NSDictionary * mydict = [result JSONValue];
-
- DescribeDictionary (mydict );
- }
- }
- Else
- {
- NSLog (@ "request is nil .");
- }
- }
-
- Void describeDictionary (NSDictionary * dict)
- {
- NSArray * keys;
- Int I, count;
- Id key, value;
-
- Keys = [dict allKeys];
- Count = [keys count];
- For (I = 0; I <count; I ++)
- {
- Key = [keys objectAtIndex: I];
- Value = [dict objectForKey: key];
- NSLog (@ "Key: % @ for value: % @", key, value );
- }
- }
-
- @ End
This is the result of parsing Json data after calling this Code: