gpt4 book ai didi

iphone - 我在 json 中发送字典,它有两个数组和多个值,但我收到响应访问被拒绝

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:46:25 26 4
gpt4 key购买 nike

我正在发送两个数组和多个值抛出 json 但是当我发送这个时我得到成功代码 200 并且它的响应显示访问被拒绝请任何人给我正确的方法来解决它 **

-(void)SaveColumnConnection
{

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURLURLWithString:@"http://xxxyyyzzzz.php"]];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:oneRowColumn,@"oneRowCols",memberTid,@"table_title_id",totalRowStr,@"totRow",rowandColumn,@"tempColName",tableOptIdArray ,@"tempOptid",companyId,@"companyid",@"savecolumniphone",@"tag",nil];
NSLog(@"dict %@",dict);
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"];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response;
NSInteger statusCode = [HTTPResponse statusCode];
if (statusCode==200) {
//Request goes in success
NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Json for post array ----------%@",str);
}
else{
///request is get failed
NSLog(@"Error Description %@",[error localizedDescription]);
}
}];
[request release];
}

最佳答案

也想查看您的 PHP 代码。无论如何,请检查以下示例是否对您有帮助...这里我没有发送任何字典值,请根据您的要求调整代码:)

NSString *jsonRequest = @"{\"username\":\"user\",\"password\":\"pwd\"}";
NSLog(@"Request: %@", jsonRequest);

NSURL *url = [NSURL URLWithString:@"http://xxxyyyzzzz.php"];

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:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody: requestData];

[NSURLConnection connectionWithRequest:[request autorelease] delegate:self];

关于iphone - 我在 json 中发送字典,它有两个数组和多个值,但我收到响应访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13971265/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com