iphone - Upload zip file with Parameters -
this question has answer here:
i trying upload file using nsurlconnection
using post
method. , need send few parameters in post username etc. trying since morning please me guys.
nsstring *urlstring = @"http://test.com/upload.aspx"; nsmutableurlrequest *request = [[[nsmutableurlrequest alloc] init] autorelease]; [request seturl:[nsurl urlwithstring:urlstring]]; [request sethttpmethod:@"post"]; nsstring *boundary = [nsstring stringwithstring:@"0xlhtalbokndarz"]; nsstring *contenttype = [nsstring stringwithformat:@"multipart/form-data; boundary=%@",boundary]; [request addvalue:contenttype forhttpheaderfield: @"content-type"]; //reading file nsstring *filepath = [[[nsbundle mainbundle] resourcepath] stringbyappendingpathcomponent:@"test.zip"]; nsdata *mydata = [nsdata datawithcontentsoffile:filepath]; nsmutabledata *body = [nsmutabledata data]; [body appenddata:[[nsstring stringwithformat:@"\r\n--%@\r\n",boundary] datausingencoding:nsutf8stringencoding]]; [body appenddata:[[nsstring stringwithformat:@"content-disposition: form-data; name=\"userfile\"; filename=\"test.zip\"\r\n"] datausingencoding:nsutf8stringencoding]]; [body appenddata:[[nsstring stringwithstring:@"content-type: application/octet-stream\r\n\r\n"] datausingencoding:nsutf8stringencoding]]; [body appenddata:mydata]; [body appenddata:[[nsstring stringwithformat:@"\r\n--%@--\r\n",boundary] datausingencoding:nsutf8stringencoding]]; [request sethttpbody:body]; nserror *returnerror = nil; nshttpurlresponse *returnresponse = nil; nsdata *returndata = [nsurlconnection sendsynchronousrequest:request returningresponse:&returnresponse error:&returnerror];
try this
Comments
Post a Comment