Objective C 写入远程 URL [英] Objective C write to Remote URL
问题描述
好的,所以我有远程主机的正确用户名/密码,并且我有一个 NSURL
对象引用服务器上的文件.
Ok, so I have the correct username / pass for a remote host, and I have a NSURL
Object referring to the file on the server.
我怎样才能通过 Objective-C 将数据写入该服务器?我找不到任何有此问题的人,因此非常感谢您的帮助!
How can I possibly write data to that server via Objective-C? I cannot find anyone with this problem, so you help would be greatly appreciated!
推荐答案
我一直在用我正在编写的程序来做这件事.答案取决于您安装的服务器及其支持的语言.如果,如我所想,您有 PHP,只需向您的服务器发送 GET 请求并指示 PHP 写入它接收到的数据.
I do it all the time with the program I am writing. The answer depends on what server you have installed and what languages it supports. If, as I think, you have PHP, just send a GET request to your server and instruct the PHP to write the data it receives.
这是我的功能:
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];
如你所见,我使用块
这篇关于Objective C 写入远程 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!