自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone應(yīng)用程序向Web服務(wù)器發(fā)送圖片 實例操作

移動開發(fā) iOS
本文介紹的是iPhone應(yīng)用程序向Web服務(wù)器發(fā)送圖片 實例操作,主要是以代碼實現(xiàn)的內(nèi)容,先來看內(nèi)容。

iPhone應(yīng)用程序向Web服務(wù)器發(fā)送圖片 實例操作是本文要介紹的內(nèi)容,本文主要是以代碼實現(xiàn),來看具體代碼。

  1. //把圖片轉(zhuǎn)換為NSData    
  2.     UIImage *image = [UIImage imageNamed:@"vim_go.png"];        
  3.     NSData *imageData = UIImagePNGRepresentation(image);    
  4.     // post url    
  5.     NSString *urlString = @"http://10.28.4.162/test-upload.php";    
  6.         
  7.     // setting up the request object now    
  8.     NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];    
  9.     [request setURL:[NSURL URLWithString:urlString]];    
  10.     [request setHTTPMethod:@"POST"];    
  11.     //    
  12.     NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];    
  13.     NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];    
  14.     [request addValue:contentType forHTTPHeaderField: @"Content-Type"];    
  15.     //    
  16.     NSMutableData *body = [NSMutableData data];    
  17.     [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];        
  18.     [body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"vim_go.png\"\r\n"] 
  19. dataUsingEncoding:NSUTF8StringEncoding]];    
  20.     [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];    
  21.     [body appendData:[NSData dataWithData:imageData]];    
  22.     [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];    
  23.     [request setHTTPBody:body];    
  24.     NSLog(@"%@",body);    
  25.     NSLog(@"%@",request);    
  26. NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];    
  27. NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];     
  28.  result_btn.text = returnString;    
  29.  
  30. /Applications/XAMPPdocs    
  31.     
  32. imac:htdocs aitracy$ cat test-upload.php     
  33.     
  34. <?php    
  35. $uploaddir = './upload/';    
  36. echo "recive a image";    
  37. $file = basename($_FILES['userfile']['name']);    
  38. $uploadfile = $uploaddir . $file;    
  39.     
  40. if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {    
  41.     echo "/uploads/{$file}";    
  42. }    
  43. ?>    

小結(jié):iPhone應(yīng)用程序向Web服務(wù)器發(fā)送圖片 實例操作的內(nèi)容介紹完了,希望本文對你有所幫助!

責(zé)任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-07-22 18:44:45

iPhone HTTPS 服務(wù)器

2017-11-10 08:58:49

Web服務(wù)器應(yīng)用程序

2011-07-26 11:13:15

iPhone PXL

2011-07-19 10:42:41

iPhone 應(yīng)用程序 模型

2011-07-19 11:12:07

iPhone 控制器

2011-07-19 10:56:15

iPhone 控制器 視圖

2011-07-26 13:23:14

iPhone 圖片 相冊

2019-05-14 09:39:07

Web服務(wù)器Web容器應(yīng)用程序服務(wù)器

2011-07-06 16:55:56

iPhone php Push

2009-06-25 17:08:14

2010-04-16 13:32:28

Win2008 R2

2018-08-23 09:16:22

2011-07-21 10:47:37

iPhone Cocoa 委托

2011-09-06 10:58:10

服務(wù)器應(yīng)用程序虛擬化

2011-07-27 14:37:33

iPhone Push Notif 服務(wù)器

2018-04-23 14:05:06

LinuxUbuntu 17.1AWFFull

2009-06-01 11:37:46

EquinoxOSGi服務(wù)器

2018-03-12 09:13:12

應(yīng)用程序服務(wù)器部署

2009-11-18 09:48:38

Windows PHP

2011-11-16 11:30:08

虛擬化虛擬服務(wù)器虛擬服務(wù)器備份
點贊
收藏

51CTO技術(shù)棧公眾號