我有个问题:
我需要使用 json 向 php 发帖,但它只响应数据类型 x-www-form-urlencoded,我使用了谷歌浏览器的邮递员而不是表单数据完成,我用这种方式但告诉我参数不正确,我需要帮助:
NSString *jsonRequest = [NSString stringWithFormat:@"j_username=%@&j_password=%@",nombre,pass];
NSURL *url = [NSURL URLWithString:urlhttp];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
NSData *requestData = [NSData dataWithBytes:[jsonRequest UTF8String] length:[jsonRequest length]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody: requestData];
[NSURLConnection connectionWithRequest:request delegate:self];