ios - 从objective-c向php发送空参数

标签 ios objective-c

我想知道的是......当我使用 post 方法向 php 发送空参数时,它发送为(null)。
让我详细说明。这是我的 ios 中的 php post 方法

NSString *urlString = [NSString stringWithFormat:@"http://localhost:8888/userinfo.php?name=%@&Email=%@&phone=%@",name,Email,phone];
 NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];

在我的应用程序中,用户不应该填写所有参数,用户应该只填写一个。因此,如果用户仅输入电话并按发送,则剩余字段将在数据库中存储为(空)而不是空的。

这就是我的应用程序在发送空参数时执行 php 文件的方式
http://localhost:8888/userinfo.php?name=(null)&Email=(null)&phone=123445435"

我想要的是
http://localhost:8888/userinfo.php?name=&Email=&phone=123445435"

这可能吗?

最佳答案

试试这个 :

NSString *urlString = [NSString stringWithFormat:@"http://localhost:8888/userinfo.php?name=%@&Email=%@&phone=%@",
 (name?name:@""),
 (Email?Email:@""),
 (phone?phone:@"")];
 NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];

条件运算符 (?:) 根据 bool 表达式的值返回两个值之一。以下是条件运算符的语法。
健康)状况 ?第一个表达式:第二个表达式;

关于ios - 从objective-c向php发送空参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25514622/

相关文章:

ios - iOS5 上的复杂 JSON

ios - 在不降低图像清晰度的情况下,应该给出哪些约束来增加相对于设备屏幕尺寸的 imageview 的尺寸

ios - 从 UITableView 中删除选定的单元格

objective-c - NSNumber 返回与原始 int 不同的值

objective-c - NSNumber 与 NSArray 的原始 int

objective-c - 我如何在像 NSLog 这样的方法中处理多个参数?

iphone:使用 Core Graphics 重写 GLPaint

iOS 静默推送通知仅在连接到 xcode 时有效

iOS 功能和按钮

objective-c - 从navigationController中弹出ViewController是否会被释放?