使用HTTP IOS 7发布图像以及文本字段数据IOS

时间:2014-11-03 11:33:28

标签: ios ios7

我可以使用我的代码成功发布文本字段但现在我想上传用户图像以及用户数据我是IOS开发的新手请帮忙

NSString *post =[[NSString alloc] initWithFormat:@"company_name=%@&designation=%@",[txtCompanyName text],[self.txtDesignation text]];



        NSURL *url=[NSURL URLWithString:@"http://profile/api/profile"];

        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

        NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];

        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];


        [request setURL:url];
        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
        [request setValue:token forHTTPHeaderField:@"X-Auth-Token"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];



        [request setHTTPBody:postData];

0 个答案:

没有答案