2014-01-29 45 views
2

這是PHP代碼:您需要的參數梅索德= GETALL一個POST電話:添加捲曲parmeter CURLOPT_USERPWD IOS

$濾鏡陣列=(); $ filters ['denomination'] ='T%';

$param = array(
    'type_element' => 'personne_morale', 
    'order' => 'denomination', 
    'limit' => 2, 
    'filtres' => $filters 
    ); 

這是不工作它給我的錯誤代碼的ios:

NSError *錯誤;

 NSURL *url = [NSURL URLWithString: @"https://www.eden-pme.com/edensoft/edenfiles/edensoft2014/api.php"]; 
     NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 




     NSURLResponse *response; 

     NSString *postString; 
     postString = [NSString stringWithFormat:@"api_public_key:api_private_key,6c8a4cf9044e48e4383b9f6a8f400055:94a337a9dd6fb58f5004f244187d5d39"]; 


     [request setURL:url]; 
     [request setHTTPMethod:@"POST"]; 
     [request setValue:postString forHTTPHeaderField:@"Content-Type"]; 
     // NSURLResponse *response; 
     NSData *res = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 

     NSArray *jsonArr = [NSJSONSerialization JSONObjectWithData:res options:kNilOptions error:&error]; 
      NSLog(@"%@",jsonArr); 

回答

1

的NSString * urlAsStr = @ 「https://www.eden-pme.com/edensoft/edenfiles/edensoft2014/api.php」;

NSMutableDictionary *dict = [[NSMutableDictionary alloc]init]; 
[dict setObject:@"6c8a4cf9044e48e4383b9f6a8f400055" forKey:@"PHP_AUTH_USER"]; 
[dict setObject:@"94a337a9dd6fb58f5004f244187d5d39" forKey:@"PHP_AUTH_PW"]; 
[dict setObject:@"getAll" forKey:@"methode"]; 
[dict setObject:@"denomination" forKey:@"order"]; 
//[dict setObject:@"2" forKey:@"limit"]; 
[dict setObject:@"personne_morale" forKey:@"type_element"]; 
[dict setObject:@"1" forKey:@"return_array"]; 

NSString *stringJson = [[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict options:0 error:nil] encoding:NSUTF8StringEncoding] autorelease]; 

NSString *postString = [NSString stringWithFormat:@"param=%@",stringJson]; 
NSData *postData = [postString dataUsingEncoding:NSUTF8StringEncoding]; 


NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlAsStr]]; 
[request setHTTPMethod:@"POST"]; 
[request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 

[request setHTTPBody:postData]; 


NSURLResponse *response; 
NSError *err; 
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err]; 

dataArray中= [NSJSONSerialization JSONObjectWithData:urlData選項:kNilOptions錯誤:& ERR];

0

試試這個,

變化[request setValue:postString forHTTPHeaderField:@"Content-Type"];

[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]]; 
+1

它不起作用 –