当前位置:编程学习 > wap >>

iPhone开发笔记(11)用ASIFormDataRequest实现图片上传

     ASIFormDataRequest是ASIHttpRequest类库的重要组成部分,最近做的毕设要实现iPhone拍照,然后将拍摄图片传到服务器端。下面是在iOS客户端使用ASIFormDataRequest以post方式进行图片上传:

    

[plain]
NSString *fileName = [[NSBundle mainBundle] pathForResource:@"test"ofType:@"jpg"]; 
NSString *url = @"http://....../upload.aspx"; 
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL: [NSURL URLWithString: url]]; 
[request setPostValue: @"MyName" forKey: @"name"]; 
[request setFile: fileName forKey: @"this_is_file"]; 
[request buildRequestHeaders]; 
NSLog(@"header: %@", request.requestHeaders); 
[request startSynchronous]; 
NSLog(@"responseString = %@", request.responseString); 
    

补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,