Objective C write to Remote URL

怎甘沉沦 提交于 2019-12-25 01:49:34

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/3935560/objective-c-write-to-remote-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!