gpt4 book ai didi

iphone - NSURLRequest 不工作

转载 作者:行者123 更新时间:2023-11-28 22:55:46 24 4
gpt4 key购买 nike

我正在使用 php 和 mysql 数据库开发 iOS 网络应用程序,我的问题是 nsurl 请求获取 php 文件的值没有响应并且不工作但是,我正在命令提示符 url 中打印并复制 url 粘贴并转到浏览器已成功更新。但是,未更新且没有响应 nsurl 请求我的代码中有什么问题?任何人都可以帮助我!

            NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://192.168.1.20:90/inkfreakz/update.php?fname=%@&lname=%@&gender=%@&dob=%@&uname=%@&email=%@&city=%@&zcode=%@&state=%@&count=%@&tattoo=%@&aboutme=%@&id=%@",txt_first.text,txt_last.text,txt_gender.text,txt_birth.text,txt_user.text,txt_email.text,txt_city.text,txt_zip.text,txt_state.text,txt_country.text,txt_tatoo.text,txt_about.text,[results objectAtIndex:13]]];
NSLog(@"%@",[NSString stringWithFormat:@"http://192.168.1.20:90/inkfreakz/update.php?fname=%@&lname=%@&gender=%@&dob=%@&uname=%@&email=%@&city=%@&zcode=%@&state=%@&count=%@&tattoo=%@&aboutme=%@&id=%@",txt_first.text,txt_last.text,txt_gender.text,txt_birth.text,txt_user.text,txt_email.text,txt_city.text,txt_zip.text,txt_state.text,txt_country.text,txt_tatoo.text,txt_about.text,[results objectAtIndex:14]]);

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:5];

NSData *urlData;
NSURLResponse *response;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];
NSString* newStr = [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];

if(newStr.length==0)
{
lbl_status.text=@"Can't Communicate with Server!";
lbl_status.hidden=NO;
[my_scroll_view setContentOffset:CGPointMake(0,0) animated:YES];
}
else {
lbl_status.text=newStr;
lbl_status.hidden=NO;
[my_scroll_view setContentOffset:CGPointMake(0,0) animated:YES];
}

谢谢!

最佳答案

我建议使用 – stringByAddingPercentEscapesUsingEncoding: 来构建您的 URL,因为它可能需要一些转义:

NSString* urlString = [NSString stringWithFormat:@"http://192.168.1.20:90/inkfreakz/update.php?fname=%@&lname=%@&gender=%@&dob=%@&uname=%@&email=%@&city=%@&zcode=%@&state=%@&count=%@&tattoo=%@&aboutme=%@&id=%@",txt_first.text,txt_last.text,txt_gender.text,txt_birth.text,txt_user.text,txt_email.text,txt_city.text,txt_zip.text,txt_state.text,txt_country.text,txt_tatoo.text,txt_about.text,[results objectAtIndex:13];

NSURL *url = [[NSURL alloc] initWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

关于iphone - NSURLRequest 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10834297/

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