这是PHP代码:您需要使用参数methode = getAll:
进行POST调用$ filters = array(); $ 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);
答案 0 :(得分: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 options:kNilOptions error:& err];
答案 1 :(得分:0)
试试这个,
将[request setValue:postString forHTTPHeaderField:@"Content-Type"];
更改为
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];