我正在开发一个应用程序,我必须在其中调用PHP Web服务。 我传递了所有提到的参数,但响应仍然是输出没有空字符串。
这些是PHP Web服务的以下参数:
method: POST
parameters: {
title fname lname conNo pwd email city state country
}
这些是成功和不成功回应的条件:
Respons:
case a: On Sucessfull Registration
{
'userName' : 'fName', 'outhProvider' : 'normal', 'status' : 'success' 'userId' : 'userId',
'title' : 'title', 'firstName' : 'fName', 'lastName' : 'lName', 'city' : 'city', 'contactNo' : 'conNo', 'state' : 'state',
'country' : 'country'
}
case b: On Duplicate Registration
{
“status” : “Data already exist” }
case c: On Data not sufficient
{
“status” : “No data supplied” }
我使用的Post方法是: -
-(void)RegisterUser
{
NSString *strnew=[[NSString alloc]init];
strnew=@"buyer";
SBJSON *json = [SBJSON new];
json.humanReadable = YES;
responseData = [[NSMutableData data] retain];
NSString *service = @"http://www.ajatus.in/ajatus_templates/Templaton/wp-content/plugins/realestate/registrationJson.php";
NSString *requestString = [NSString stringWithFormat:@"{\"title\":\"%@\",\"fName\":\"%@\",\"lName\":\"%@\",\"conNo\":\"%@\",\"pwd\":\"%@\",\"email\":\"%@\",\"city\":\"%@\",\"state\":\"%@\",\"country\":\"%@\"}",titlename.text,fname.text,lname.text,contactno.text,password.text,email.text,city.text,state.text,country.text];
NSData *requestData = [NSData dataWithBytes: [requestString UTF8String] length: [requestString length]];
NSString *urlLoc=@"";
urlLoc = [urlLoc stringByAppendingString:service];
NSLog(@"URL:- %@",urlLoc);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:
[NSURL URLWithString: urlLoc]];
NSString *postLength = [NSString stringWithFormat:@"%d", [requestData length]];
[request setHTTPMethod: @"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody: requestData];
self.connection = [NSURLConnection connectionWithRequest:request delegate:self];
}
答案 0 :(得分:0)
你必须使用一些键值来获取所有数据,例如这行代码:
NSString* latestvalue = [[[json objectForKey:@"countries"] objectAtIndex:0] objectForKey:@"countryName"];