c# - upload HttpPostedFileBase file along with some parameters -


i have consume webservice have method this:

submituser(userreg user, httppostedfilebase image) {    // webservice side processing` } 

userreg custom class on webservice side have several properties username,id,latitude,longitude etc..

i have submit data through method , save webservice response after execution of method. action perform on button click. how can all.

i using .net framework 4.5 , mvc 4

note: end user of webservice

update1: submituser webservice side method , url is

somepage.com/api/submituser

you use httpclient can send multipart/form-data encoded request:

byte[] imagedata = ... var requestcontent = new multipartformdatacontent(); var imagecontent = new bytearraycontent(imagedata); imagecontent.headers.contenttype = mediatypeheadervalue.parse("image/jpeg");  // add image requestcontent.add(imagecontent, "image", "image.jpg");  // add additional parameters bound userreg object requestcontent.add(new stringcontent(httputility.urlencode("value1")), "param1"); requestcontent.add(new stringcontent(httputility.urlencode("value2")), "param2"); requestcontent.add(new stringcontent(httputility.urlencode("value3")), "param2.subparam1");  var client = new httpclient(); var res = client.postasync("http://your_web_service_endpoint", requestcontent).result; 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -