Receive data through WebAPI Post and webapipost

Source: Internet
Author: User

Receive data through WebAPI Post and webapipost

Recently, I am writing a webapi interface for an open-source marketplace. I have encountered some problems due to my new contact, such as receiving post data. Three methods are provided for online data query.

1. encapsulate multiple data objects into one object for receiving ([frombody] labels can only be used for one parameter. For details, refer to the previous blog)

2. Use formcollection to receive data (the key here is that all the information found on the internet is received with formcollection. In actual testing, the request is successful, but no data can be obtained. I have been wondering whether I have done wrong, and later found that this type of introduction source from a blog http://www.dotblogs.com.tw/regionbbs/archive/2013/01/10/web.api.method.and.routing.aspx#72397, after consulting the blogger, found that it was wrong. In webapi, The FormDataCollection of System. Net. Http. Formatting must be used)

3. Use JObject to declare

If JSON is required, we can use JObject in Json. NET to implement:

Then, the POST Content must be in JSON format and the required Content-Type must be set to application/json ),

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.