【问题标题】:How to pass parameters in Php web service?如何在 PHP Web 服务中传递参数?
【发布时间】:2013-02-14 05:23:20
【问题描述】:

我正在开发一个应用程序,我必须在其中调用 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];

}

【问题讨论】:

    标签: objective-c web-services nsurlrequest


    【解决方案1】:

    你必须使用一些键值来获取所有数据,就像这行代码:

    NSString* latestvalue = [[[json objectForKey:@"countries"] objectAtIndex:0] objectForKey:@"countryName"];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-05
      • 2018-12-06
      • 2019-05-19
      • 1970-01-01
      • 1970-01-01
      • 2017-06-20
      • 2012-04-15
      • 2011-02-20
      相关资源
      最近更新 更多