AFNetworking Post请求使用



AFNetworking 2.4.0 Post请求使用:上传图片+文字

http://cocoadocs.org/docsets/AFNetworking/2.4.0/


#import  "AFNetworking.h"


-( void )postRequest{

 
          NSString  *str =  @"url地址" ;

    
NSDictionary  *userInfo =  @{  
                                
@"pic" @"" ,
                                
@"content" @"asdhyfmhmfsdfsdf" ,
                                

                                
} ;
    

   
   NSURL  *imagePath = [ NSURL   fileURLWithPath :[[ NSBundle   mainBundle pathForResource : @"ko"   ofType : @"png" ]];
     NSURL  *imagePath2 = [ NSURL   fileURLWithPath :[[ NSBundle   mainBundle pathForResource : @"1"   ofType : @"png" ]];
//    NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ko" ofType:@"png"]];
    
//     NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"ko.png" withExtension:nil];
    
    
AFHTTPRequestOperationManager  *manager = [ AFHTTPRequestOperationManager   manager ];
    [manager 
POST :str  parameters :userInfo  constructingBodyWithBlock :^( id < AFMultipartFormData > formData) {
        
        [formData 
appendPartWithFileURL :imagePath  name : @"pic"   error : nil ];
        [formData  appendPartWithFileURL :imagePath2  name : @"pic"   error : nil ];
//        [formData appendPartWithFormData:data name:@"pic"];
        
        
    } 
success :^( AFHTTPRequestOperation  *operation,  id  responseObject) {
       
          
NSLog ( @"Success: %@" , responseObject);
        
    } 
failure :^( AFHTTPRequestOperation  *operation,  NSError  *error) {
        
         
NSLog ( @"Error: %@" , error);
        
    }];

 


}

之前一直报错,打印错误信息:Error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: not found (404)" UserInfo=0x10c2573a0 {NSUnderlyingError=0x10b9524c0 "Request failed: unacceptable content-type: text/html", com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x10b93b0b0> {

404的错误,我以为是我这边的url不对才导致的404错误。后来才知道是服务器端口改了。以后做网络请求的时候,一定要先把url用浏览器打开看看能不能成功














评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值