ios - Post Two images to Web server -
below code wrote sending 2 images. failed find code why not working. new ios , stackoverflow. still thinking code ok. help me find mistake. how modify code able send 2 images different services(each service have separate url).
nsstring *requeststring =[nsstring stringwithformat:@"requestuserid=%@&categoryid=%@&continent=%@&country=%@&city=%@&gender=%@&imagename=%@&agerange=%@",userid,categoryid1,continenttextfield.text,countrytextfield.text,citytextfield.text,gendertext.text,imagename,agetextfield.text]; nslog(@"request%@",requeststring); nsstring *url=[nsstring stringwithformat:@"http://37.187.152.236/userimage.svc/insertobjectimage?%@",requeststring]; nsmutableurlrequest *request = [[nsmutableurlrequest alloc] init] ; [request seturl:[nsurl urlwithstring:url]]; [request sethttpmethod:@"post"]; // create 'post' mutablerequest info , other image attachment. nsstring *boundary = @"---------------------------14737809831466499882746641449"; nsstring *contenttype = [nsstring stringwithformat:@"multipart/form-data; boundary=%@", boundary]; [request setvalue:contenttype forhttpheaderfield:@"content-type"]; nsdata *data = uiimagejpegrepresentation(chosenimage, 0.2f); [request addvalue:@"image/jpeg" forhttpheaderfield:@"content-type"]; nsmutabledata *body = [nsmutabledata data]; [body appenddata:[nsdata datawithdata:data]]; [request sethttpbody:body]; nsdata *returndata; nsstring *returnstring = [[nsstring alloc] initwithdata:returndata encoding:nsutf8stringencoding]; nslog(@"ret: %@",returnstring); nsurlconnection *connreq = [nsurlconnection connectionwithrequest:request delegate:self]; if (connreq) { nslog(@"connection sucessful"); receiveddata = [[nsmutabledata alloc]init]; } else { nslog(@"failed"); } nshttpurlresponse *response = nil; nserror *error = nil; nsdata *respdata = [nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&error]; nslog(@"status code: %d", [response statuscode]); nslog(@"respdata%@",respdata); if ([response statuscode]==200) {
self.userid=[[nsuserdefaults standarduserdefaults]objectforkey:@"sendd"]; nslog(@"recieveddata%@",receiveddata); nsstring *requeststring1 =[nsstring stringwithformat:@"requestuserid=%@&imageid=%@&=imagename%@",userid,compareid,imagename]; nslog(@"%@",requeststring1); nsstring *url1=[nsstring stringwithformat:@" http://37.187.152.236/userimage.svc/updateobjectimage?%@",requeststring1]; nsmutableurlrequest *request1 = [[nsmutableurlrequest alloc] init] ; [request1 seturl:[nsurl urlwithstring:url1]]; [request1 sethttpmethod:@"post"]; // create 'post' mutablerequest info , other image attachment. nsstring *boundary = @"---------------------------14737809831466499882746641449"; nsstring *contenttype = [nsstring stringwithformat:@"multipart/form-data; boundary=%@", boundary]; [request1 setvalue:contenttype forhttpheaderfield:@"content-type"]; nsdata *data = uiimagejpegrepresentation(chosenimage, 0.2f); [request1 addvalue:@"image/jpeg" forhttpheaderfield:@"content-type"]; nsmutabledata *body1 = [nsmutabledata data]; [body1 appenddata:[nsdata datawithdata:data]]; [request sethttpbody:body1]; nsdata *returndata; nsstring *returnstring = [[nsstring alloc] initwithdata:returndata encoding:nsutf8stringencoding]; nslog(@"ret: %@",returnstring); nsurlconnection *connreq = [nsurlconnection connectionwithrequest:request delegate:self]; if (connreq) { nslog(@"connection sucessful"); receiveddata = [[nsmutabledata alloc]init]; } else { nslog(@"failed"); } nshttpurlresponse *response = nil; nserror *error = nil; nsdata *respdata = [nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&error]; nslog(@"status code: %d", [response statuscode]); nslog(@"respdata%@",respdata); homeviewcontroller *homvew =[[homeviewcontroller alloc]initwithnibname:@"homeviewcontroller" bundle:nil]; self.navigationitem.hidesbackbutton = yes; [self.navigationcontroller pushviewcontroller:homvew animated:yes]; } ios objective-c ios7
No comments:
Post a Comment