中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

iOS通過(guò)http post上傳圖片

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
//ASIFormDataRequest方式 POST上傳圖片
-(NSDictionary *)addPicWithDictionary:(NSDictionary *)sugestDic{
 
    NSDictionary *tempDic=nil;
     
    NSString *url=[NSString stringWithFormat:@"http://182.50.0.62:8095/xianServer/upload/uploadImage?clientType=mobile"];
     
    form = [[[ASIFormDataRequest alloc]
             initWithURL:[NSURL URLWithString:url]] autorelease];
    [form setTimeOutSeconds:60.0];
    form.delegate = self;
    //添加拍照?qǐng)D
     
     
    //分界線的標(biāo)識(shí)符 
    NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x"; 
    //分界線 --AaB03x 
    NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY]; 
    //結(jié)束符 AaB03x-- 
    NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
    //添加拍照?qǐng)D片
    imageView.image=[UIImage imageNamed:@"btn_done_down@2x.png"];
    NSData* data = UIImagePNGRepresentation(imageView.image);
    NSLog(@"%@",data);
    //http body的字符串  
    NSMutableString *body=[[NSMutableString alloc]init];  
    //參數(shù)的集合的所有key的集合  
    NSArray *keys= [sugestDic allKeys];  
     
    //遍歷keys  
    for(int i=0;i<[keys count];i++)  
    {  
        //得到當(dāng)前key  
        NSString *key=[keys objectAtIndex:i];  
        //如果key不是pic,說(shuō)明value是字符類(lèi)型,比如name:Boris  
        if(![key isEqualToString:@"files"])
        {  
            //添加分界線,換行  
            [body appendFormat:@"%@\r\n",MPboundary];  
            //添加字段名稱(chēng),換2行  
            [body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];  
            //添加字段的值  
            [body appendFormat:@"%@\r\n",[sugestDic objectForKey:key]];              
        }  
    }  
    if (imageView.image) {
        ////添加分界線,換行  
        [body appendFormat:@"%@\r\n",MPboundary];
        //聲明pic字段,文件名為boris.png  
        [body appendFormat:@"Content-Disposition: form-data; name=\"files\"; filename=\"boris.png\"\r\n"];  
        //聲明上傳文件的格式  
        [body appendFormat:@"Content-Type: image/png\r\n\r\n"];
    }
     
    //聲明結(jié)束符:--AaB03x-- 
    NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary]; 
    //聲明myRequestData,用來(lái)放入http body 
    NSMutableData *myRequestData=[NSMutableData data]; 
    //將body字符串轉(zhuǎn)化為UTF8格式的二進(jìn)制 
    [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]]; 
    //將image的data加入 
    [myRequestData appendData:data]; 
    //加入結(jié)束符--AaB03x-- 
    [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
    //設(shè)置HTTPHeader中Content-Type的值 
    NSString *content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
     
    [form addRequestHeader:@"Content-Type" value:content];
    [form addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%d", [myRequestData length]]];
    [form setRequestMethod:@"POST"];
    [form startAsynchronous];
    [form setDidFailSelector:@selector(requestBeFailed:)];
    [form setDidFinishSelector:@selector(requestBeFinished:)];
    // 解析取得的結(jié)果
    return tempDic; 
}

標(biāo)簽: isp

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:iOS文件操作的代碼

下一篇:iOS視圖翻頁(yè)過(guò)渡效果