简体   繁体   中英

How to Post a JSON and an Image to WCF (Using Content-type: application/JSON)

I am trying to post an Image with JSON object to wcf service in a Request.

Also i need to have Contant-Type: application/json on the request. How can i do that?

Can anyone please show me how the request will look like and also how do i receive in WCF.

Currently i am receiving like that- 在此处输入图片说明

And sending request like- 在此处输入图片说明

I would like to be able to do something like that- 在此处输入图片说明

Any suggestion or link or code would be appreciated. Thanks

Just convert image binary data to base64 and send it as a regular field:

var imageBin = new byte[]{}; // need image data here
var base64Img = Convert.ToBase64String(imageBin);
var json = 
@"{ 
    'someData' : 'someValue',
    'image' : '" + base64Img + @"'
}";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM