Objective C 写入远程 URL

发布于 2024-09-27 04:06:22 字数 128 浏览 10 评论 0原文

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

我怎样才能通过 Objective-C 将数据写入该服务器?我找不到任何有此问题的人,所以您的帮助将不胜感激!

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.

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴者 2024-10-04 04:06:22

我一直在编写我的程序时这样做。答案取决于您安装的服务器及其支持的语言。正如我所想,如果您有 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];

如你所见,我使用块

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.

This is a function of mine:

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

On the client side:

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];

As you can see I use blocks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文