I am using and Web API to perform some task, and when the task is finished the API return me a object in the OK method.
The code:
[Route("upload")]
[HttpPost]
public async Task<IHttpActionResult> PostFormData()
{
//Create the object
var blob = new BlobUploadModel();
//Do some tasks
...
//Return
return Ok(blob);
}
How can I get this blob object in the response which, I think, should be a IHttpActionResult?
Any help is appreciated!
Web API will serialize your instance of BlobUploadModel into the MIME type specified in the client request Accept:
header. The serialized blob will then be attached to the response body.
Your client that calls this action will need to deserialize the contents of the response body back to a BlobUploadModel. JSON.Net is a great library for serialization/deserialization between JSON objects and CLR objects. To deserialize a JSON response back to a BlobUploadModel using JSON.Net you can use the following:
var blob = JsonConvert.DeserializeObject<BlobUploadModel>(responseBody);
Keep in mind that your client project will need to know what a BlobUploadModel is.
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.