ios - Send image to .NET web service -


i developing ios application using .net web service. in 1 of web services, have send image httppostedfilebase in parameter called "file", return image url , status parameters response. not sure httppostedfilebase. trying send bytes. getting image url null ws. guess ws call works fine, problem in way send image. using following code append image data http body.

nsdata *imagedata = uiimagejpegrepresentation(image, 1); [postdata appenddata:[[nsstring stringwithformat:@"--%@\r--\n",boundary] datausingencoding:nsutf8stringencoding]]; [postdata appenddata:[@"content-disposition: form-data; name=\"file\"; filename=\"file.jpeg\"\r\n" datausingencoding:nsutf8stringencoding]]; [postdata appenddata:[@"content-type: image/jpeg\r\n\r\n" datausingencoding:nsutf8stringencoding]]; [postdata appenddata:imagedata]; [request addvalue:@"application/octet-stream" forhttpheaderfield:@"content-type"]; [request addvalue:[nsstring stringwithformat:@"%i", [postdata length]] forhttpheaderfield:@"content-length"]; [postdata appenddata:[[nsstring stringwithformat:@"--%@\r--\n",boundary] datausingencoding:nsutf8stringencoding]]; 

please let me know how can working. let me know if need anymore detail.

thanks.

sorry guys. problem in http headers. link (ios upload image , text using http post) posted @fahriazimov above helped me. bad, confused there going different format .net web services.

i had send image normal web services. working code below:

nsstring *contenttype = [nsstring stringwithformat:@"multipart/form-data; boundary=%@",boundary]; [request addvalue:contenttype forhttpheaderfield: @"content-type"];   [postdata appenddata:[[nsstring stringwithformat:@"--%@\r\n", boundary] datausingencoding:nsutf8stringencoding]]; [postdata appenddata:[[nsstring stringwithformat:@"content-disposition: form-data; name=\"%@\"; filename=\"image.jpg\"\r\n", @"file"] datausingencoding:nsutf8stringencoding]]; [postdata appenddata:[@"content-type: image/jpeg\r\n\r\n" datausingencoding:nsutf8stringencoding]]; [postdata appenddata:imagedata]; [postdata appenddata:[[nsstring stringwithformat:@"\r\n"] datausingencoding:nsutf8stringencoding]]; [postdata appenddata:[[nsstring stringwithformat:@"--%@--\r\n", boundary] datausingencoding:nsutf8stringencoding]]; 

thanks lot everyone's help.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -