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

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

     

    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);
     

     下一篇我将用.net实现服务器端接收图片并保存到服务器的某个路径下。

你可能感兴趣的:(.net,服务器,header,File,url,iPhone)