ios - AFHTTPRequestOperationManager file upload returns 500 server error -


im trying upload camera taken photo webservice afnetworking.

this upload part code :

cgsize newsize = cgsizemake(500.0f, 500.0f); uigraphicsbeginimagecontext(newsize); [_imagedata drawinrect:cgrectmake(0,0,newsize.width,newsize.height)]; uiimage* newimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); nsdata *imgdata = uiimagejpegrepresentation(newimage, 0.9f);      afhttprequestoperationmanager *manager = [afhttprequestoperationmanager manager];     nsdictionary *parameters = @{@"user": "test_user"};     [manager post:@"http://www.mywebsite.com/webservice.aspx" parameters:parameters constructingbodywithblock:^(id<afmultipartformdata> formdata) {         manager.responseserializer = [afhttpresponseserializer serializer];         [formdata appendpartwithformdata:imgdata name:@"image"];     } success:^(afhttprequestoperation *operation, id responseobject) {         nslog(@"success: %@", responseobject);     } failure:^(afhttprequestoperation *operation, nserror *error) {         nslog(@"error: %@", error);     }]; 

im using asp.net webservice.

this server side code :

    string user = server.urldecode(request["user"]),     sqlparameter prmuser = sc.parameters.add("@user", sqldbtype.varchar);     prmuser.direction = parameterdirection.input;     prmuser.value = user;       httpfilecollection myfilecollection = request.files;     if (myfilecollection != null && myfilecollection.count > 0 && myfilecollection[0] != null)     {         sqlparameter prmimage = sc.parameters.add("@image", sqldbtype.image);         prmimage.direction = parameterdirection.input;         byte[] buf = new byte[myfilecollection[0].contentlength];         myfilecollection[0].inputstream.read(buf, 0, myfilecollection[0].contentlength);         prmphoto.value = buf;      } sc.executenonquery(); 

now everytime run program error apears :

error: error domain=com.alamofire.error.serialization.response code=-1011 "request failed: internal server error (500)" userinfo=0x1555ff60 {com.alamofire.serialization.response.error.response=<nshttpurlresponse: 0x16a94010> { url: http://www.mywebsite.com/webservice.aspx } { status code: 500, headers {     connection = close;     "content-length" = 3420;     "content-type" = "text/html; charset=utf-8";     date = "wed, 01 apr 2015 15:56:21 gmt";     server = "microsoft-iis/8.5";     via = "1.1 magellan-front (squid/3.5.1)";     "x-aspnet-version" = "4.0.30319";     "x-cache" = "miss magellan-front";     "x-powered-by" = "asp.net"; } }, nserrorfailingurlkey=http://www.mywebsite.com/webservice.aspx, nslocalizeddescription=request failed: internal server error (500), 

the detailed error :

[httprequestvalidationexception (0x80004005): potentially dangerous request.form value detected client (image=&quot;...�5�Ƨ&amp;�����&lt;i �(�ep��k�,�=mp�...&quot;).] 

also webservice works android httpfileupload method.

i trying find basics of this, here link

what seems code client side seems have issue. why don't try using appendpartwithfileurl:name:filename:mimetype:error:, , if doesn't work issue has server side.

i don't know asp.net, once verify way how trying read file. here link in found interesting might wanna try implementing.

the enumerator on httpfilecollection returns keys (names) of files, not httppostedfilebase objects. once key, use item ([]) property key (filename) httppostedfilebase object.

foreach (string filename in request.files) {     httppostedfilebase file = request.files[filename];      ... }  

let me know if doesn't work.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -