代码之家  ›  专栏  ›  技术社区  ›  Richard J. Ross III

目标C写入远程URL

  •  0
  • Richard J. Ross III  · 技术社区  · 14 年前

    好的,我有远程主机的正确用户名/密码,并且 NSURL

    我怎样才能通过Objective-C向服务器写入数据?我找不到有这个问题的人,所以非常感谢你的帮助!

    1 回复  |  直到 14 年前
        1
  •  1
  •   gurghet    14 年前

    我一直在用我正在写的程序。答案取决于您安装了什么服务器以及它支持什么语言。如我所想,如果您有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];
    

    如你所见,我用积木

    推荐文章