在iOS中将字符串发送到网络服务器?

时间:2010-08-24 03:34:38

标签: iphone macos ios

我想向webserver(PHP webserver)发送一个String(一个长字符串,大约600个字符)。我可以使用NSURLRequest和NSURLConnection将其发送到我的PHP网络服务器吗?

1 个答案:

答案 0 :(得分:2)

正是你要找的东西

http://forums.macrumors.com/showthread.php?t=689884

NSString *params = [[NSString alloc] initWithFormat:@"foo=longstringdatagoeshere"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];

记得实现委托方法

http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html#//apple_ref/doc/uid/20001697-DontLinkElementID_17