how to post an image to the web server

后端 未结 4 1242
旧时难觅i
旧时难觅i 2021-01-13 10:38

I am working with web services using json parsing. I am able to get images from the web services, can someone help me how to post an image? How i can post an image to the we

4条回答
  •  臣服心动
    2021-01-13 11:27

    it will be something along the lines of this...

    NSMutableURLRequest *mutableRequest = [[NSMutableURLRequest alloc] initWithURL:@"you url"];
    
    [mutableRequest addValue:@"image/jpeg" forHTTPHeaderField: @"Content-Type"];
    
    NSMutableData *body = [NSMutableData data];
    
    [body appendData:[NSData dataWithData:UIImageJPEGRepresentation(self.image, 0.9)]];
    
    [mutableRequest setHTTPBody:body];
    
    NSURLResponse *response;
    NSError *error;
    
    (void) [NSURLConnection sendSynchronousRequest:mutableRequest returningResponse:&response error:&error];
    

    Thanks

提交回复
热议问题