当字符串包含空格时应用程序不会更新数据库
我遇到了一个奇怪的问题。我建立了一个 mysql 数据库,用户可以通过应用程序存储他的联系人。他只需点击一个按钮即可添加他的联系信息。然后,数据被添加到数据库中。
但是,当联系人信息的名字、姓氏或号码之间有空格时,应用程序将拒绝接受该数据。我没有收到错误消息或类似的信息,但也没有得到任何确认。该记录在数据库中不存在。
我的php文件没有问题(该文件绝对正确,我在这里检查了两次)。 这是我的代码:
NSString *strURL = [NSString stringWithFormat:@"http://www.abc.com/phpFile.php?number=%@&name=%@&lastname=%@", number, firstName, lastName];
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
NSLog(@"%@", strResult);
I ran into a weird problem. I built a mysql database where the user can store his contacts through an app. He just adds his contact information by clicking on a button. Then, the data is added to the database.
However, when the contact's information has spaces between his first name, last name or number the app refuses to accept the data. I dont get an error message or anything like that, but I also dont get any confirmation. The record does not exist in the database.
There is no problem with my php file (The file is definitely correct, I got it checked here, twice).
Here is my code:
NSString *strURL = [NSString stringWithFormat:@"http://www.abc.com/phpFile.php?number=%@&name=%@&lastname=%@", number, firstName, lastName];
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
NSLog(@"%@", strResult);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
URI 中不允许使用空格字符。使用 %20 对空格进行编码。还有其他字符也不允许作为 URI 的一部分。查找 URI 编码。
The space character is not allowed in a URI. Use %20 to encode the space. There are other characters that are also not allowed as part of the URI. Look up URI encoding.