1

这是我的代码,我的代码正在运行,但我的问题是当我尝试NSString *postString = @"username=example&firstlastname=example";在它说示例的位置传递变量而不是名称时,我想要 = 一个 TextField 值,那么我该怎么做呢?我尝试过发布字符串附加字符串,但它没有用。请帮忙

NSURL *aUrl= [NSURL URLWithString:@"http://xxxx/iqueueinsertinjoinq.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:aUrl
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
NSString *postString = @"username=example&firstlastname=example";

[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];

//NSURLConnection *connection= [[NSURLConnection alloc] initWithRequest:request delegate:self];
 [[NSURLConnection alloc] initWithRequest:request delegate:self ];}
4

1 回答 1

1

如果我正确理解您的问题,您想要的是:更改:

NSString *postString = @"username=example&firstlastname=example";

至:

NSString *username = @"foo";
NSString spokenname = @"bar";
NSString *postString = [NSString stringWithFormat:@"username=%@&firstlastname=%@", username, spokenname];

NSString 的 stringWithFormat:允许在格式字符串中进行变量替换。在我的示例中,“username”是包含用户名的 NSString 变量,“spokenname”是 firstnamelastname 字符串。

于 2013-10-08T09:29:02.750 回答