i trying upload image server afnetworking. code below. server not written me not sure if code wrong or went wrong server side , im trying troubleshoot want know inside body part of request, when try log body nothing, doing wrong? when code runs end in success block server returns nothing me, , photo doesn't uploaded.
afhttpclient *client = [[afhttpclient alloc] initwithbaseurl:baseurl]; [client registerhttpoperationclass:[afhttprequestoperation class]]; nsdictionary *params = [[nsdictionary alloc]initwithobjectsandkeys: title, @"title", desc, @"description", nil]; nsmutableurlrequest *request = [client multipartformrequestwithmethod:@"post" path:@"myphotoapp/upload" parameters:params constructingbodywithblock: ^(id <afmultipartformdata>formdata) { [formdata appendpartwithfiledata:imagedata name:@"photo" filename:@"photo.png" mimetype:@"image/png"]; }]; nslog(@"request: %@", request); nslog(@"body: %@", [[nsstring alloc] initwithdata:request.httpbody encoding:nsutf8stringencoding]); afhttprequestoperation *operation = [[afhttprequestoperation alloc] initwithrequest:request]; [operation setcompletionblockwithsuccess:^(afhttprequestoperation *operation, id responseobject) { nslog(@"success:%@", operation.responsestring); } failure:^(afhttprequestoperation *operation, nserror *error) { nslog(@"fail: %@", error.description); }]; [operation start];
as side note, there online reading or book understand more how http requests made because don't quite understand it.
Comments
Post a Comment