c# - REST API sending images to requests -


i have function through calling rest api. need pass image in request. how achieve that?

for ex :

public int save(image image) {     httpwebrequest req = (httpwebrequest)webrequest.create(url);     req.method = "post";     httpwebresponse response = (httpwebresponse)req.getresponse(); } 

here, how pass 'image' request 'req'?

try use like:

req.contenttype = "multipart/form-data";  using (var ms = new memorystream()) {     image.save(ms, system.drawing.imaging.imageformat.jpeg); //if jpeg     string encoded = convert.tobase64string(ms.toarray());     byte[] reqdata = encoding.utf8.getbytes(encoded);     using (var stream = req.getrequeststream())     {         stream.write(reqdata, 0, reqdata.length);     } } 

Comments