上傳圖片和資料到伺服器 是最基本的需求了,有些學IOS的 可能對伺服器怎麼接收圖片這塊不太瞭解。 所以今天 我把伺服器的代碼 也拷過來了。。。 只會ASP.NET 。。 PHP 和J2EE 應該差不多 都是幾句話的事 IOS端代碼: NSString* path = [[NSBundlemainBundle]pathForResource:@"iphone1-1-10"ofType:@"png"];#pragma mark 使用ASIHttpRequest 上傳圖片和資料 ASIFormDataRequest* request = [ASIFormDataRequestrequestWithURL:[NSURLURLWithString:@"http://192.168.0.1/IOSUPLOAD/default.aspx"]]; [requestaddFile:pathforKey:@"img"]; [requestaddPostValue:@"asihttp"forKey:@"name"]; [request setCompletionBlock:^{ NSLog(@"%@",request.responseString); }]; [requestsetFailedBlock:^{ NSLog(@"asi error: %@",request.error.debugDescription); }]; [request startAsynchronous];#pragma mark 使用MKNetworkKit 上傳圖片和資料 MKNetworkEngine* engine = [[[MKNetworkEnginealloc]init]autorelease]; NSDictionary* postvalues = [NSDictionarydictionaryWithObjectsAndKeys:@"mknetwork",@"name",nil]; MKNetworkOperation* op = [engineoperationWithURLString:@"http://192.168.0.1/IOSUPLOAD/default.aspx"params:postvalueshttpMethod:@"POST"]; [opaddFile:pathforKey:@"img"]; [opaddCompletionHandler:^(MKNetworkOperation *completedOperation) { NSLog(@"%@",request.responseString); }errorHandler:^(MKNetworkOperation *completedOperation,NSError *error) { NSLog(@"mknetwork error : %@",error.debugDescription); }]; [engineenqueueOperation:op]; //看上去就是跟樣本的差不多 ASP.NET服務端的代碼:[csharp] www.2cto.comprotected void Page_Load(object sender, EventArgs e) { if (Request.Files.Count == 0) { Response.Write("none file"); } else { HttpPostedFile file = Request.Files["img"]; String filename = Request.Form["name"]; file.SaveAs(MapPath("~/"+filename+".png")); Response.Write("ok"); } }