我正在使用以下代码从使用我的网络服务的iOS开发人员那里获取数组。
$handle = fopen('php://input','r');
$jsonInput = fgets($handle);
$decoded = json_decode($jsonInput,true);
我想为安卓创建相同的内容,然后我使用
$_POST
并获取数组输入。
获取数组输入的常用方法是什么?这样就不需要编写两个不同的代码。
和使用以下代码的 iOS 开发人员
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:WEB_URL]];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"username",@"username",@"password",@"password",textboxMobile.text,@"mobile",textboxEmail.text,@"email",deviceidnew,@"device_id",cityid,@"city_id",[NSString stringWithFormat: @""],@"othercity",areaidstore,@"area_id",[NSString stringWithFormat: @""],@"otherarea",self.textboxName.text,@"name",khidmatarraylist,@"khidmat_id",userid,@"user_id",@"editprofileiphone",@"tag",nil];
SBJSON *parser =[[SBJSON alloc] init];
NSString *jsonString = [parser stringWithObject:dict];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
我检查了这些链接:
什么是"php://input"?它主要出现在网络服务中
我正在用json发送字典,它有两个数组和多个值,但我的响应访问被拒绝
但没有那么多帮助有什么建议吗?
提前致谢
我想你在 iOS 方面错过了这一点,
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];