好的,所以我有正确的远程主机用户名 /通行证,我有一个 NSURL 对象参考服务器上的文件。

如何通过Objective-C将数据写入该服务器?我找不到这个问题的人,因此您将不胜感激!

有帮助吗?

解决方案

我一直在编写的程序中一直这样做。答案取决于您已安装了哪些服务器以及它支持的语言。如我所想,如果您有PHP,只需将GET请求发送到您的服务器,并指示PHP编写收到的数据。

这是我的功能:

function checkInfo() {
    $username = $_GET['username'];
    $password = $_GET['password'];
    connectToDataBase();
    return returnSuccessObjectOn(isLoginInfoValid($username, $password));
}

在客户端:

NSURL *url = [NSURL URLWithString:kRequestLink];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:TIMEOUT];
OARequestParameter *reqCodeParameter = [[OARequestParameter alloc] initWithName:kParamReqCode value:[NSString stringWithFormat:@"%d",reqCode]];
[par addObject:reqCodeParameter];
[data enumerateKeysAndObjectsUsingBlock:composeRequestBlock];
[req setParameters:par];
NSLog(@"Sendind GET request: %@", [req description]);
activeConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self startImmediately:YES];

如您所见,我使用块

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top