Post Data but GET Method json -ios

2019-08-04 08:45发布

how can i use the get method to post data on an api link with 6 values and a json format?

im really fuzzled. im doing this for days . is it best to have 6 textfields that will be used to write the value and a button to indicate post data?

check out my code and please help.

-(IBAction)postDataPressed
{

    NSString *urlString = @"http://192.168.18.8/apisample2/friendb.php?fm=jsn";
    NSURL *url = [NSURL URLWithString:urlString];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

    [request setPostValue:user.text forKey:@"un"];
    [request setPostValue:pass.text forKey:@"pd"];
    [request setPostValue:gender.text forKey:@"gd"];
    [request setPostValue:age.text forKey:@"ag"];
    [request setPostValue:status.text forKey:@"st"];
    [request setPostValue:lookfor.text forKey:@"lf"];

    [request setRequestMethod:@"GET"];
    [request setCompletionBlock:^{
    NSString *responseString = [request responseString];
    NSLog(@"Response: %@", responseString);
    }];
    [request setFailedBlock:^{
        NSError *error = [request error];
        NSLog(@"Error: %@", error.localizedDescription);
    }];
    [request setDidFinishSelector:@selector(requestFinished:)];
    [request setDidFailSelector:@selector(requestFailed:)]; 
    [request startAsynchronous];


}

i hope someone will help.

1条回答
该账号已被封号
2楼-- · 2019-08-04 09:05
NSString *request_url = [NSString stringWithFormat: @"http://192.168.18.8/apisample2/friendb.php?fm=jsn&un=%@&pd=%@&gd=%@&ag=%@&st=%@&lf=%@",
    user.text, pass.text, gender.text, age.text,status.text,lookfor.text];
NSURL *url = [NSURL URLWithString:request_url];
ASIHttpRequest *request = [ASIHttpRequest requestWithURL:url];
request.delegate = self;
....

HTTP Get method only accept data in url, called query string, so you have to build query string yourself.

查看更多
登录 后发表回答