How to upload a file to the server in iPhone SDK?

后端 未结 2 1096
隐瞒了意图╮
隐瞒了意图╮ 2020-12-21 06:43

I want to send a file to server in iPhone. Is there any iPhone API to implement that functionality?

2条回答
  •  余生分开走
    2020-12-21 07:35

    ASIHTTPRequest is a wrapper around the network APIs and makes it very easy to upload a file. Here's their example (but you can do this on the iPhone too - save images to "disk" and later upload them.

    ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
    [request setPostValue:@"Ben" forKey:@"first_name"];
    [request setPostValue:@"Copsey" forKey:@"last_name"];
    [request setFile:@"/Users/ben/Desktop/ben.jpg" forKey:@"photo"];
    

提交回复
热议问题