Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
234 views
in Technique[技术] by (71.8m points)

nsurl - Objective C write to Remote URL

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...