API Dev Q&A
Q: use which sample api
A: Choose a sample API of the language you are familiar with based on your own technology stack. Another prerequisite is that you need to have a certain degree of understanding of the http protocol and know concepts such as http header/content-type. It is best to have relevant experience in API program server deployment.
Q: The received data is all 0
A: If use springboot framework, adds consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE} to the API won’t work. The result of the data received by your program will be as shown in the figure
Q: configure content-type in nginx
A: Assuming your API address is http://xxx.baidu.com/4gtest/pb/upload, add the following settings to the nginx configuration file
Q: why only Java sample API need configure content-type,and others not
A: The need to configure content-type is caused by two factors: 1. The content-type set for data uploaded by the watch is application/x-www-form-urlencoded in the form format (limited by the hardware 4G module), but the content is not submitted in application/x-www-form-urlencoded (in binary format or json format). 2. When the spring framework receives a request with content-type application/x-www-form-urlencoded, it will parse the data in the form format. However, parsing the data in the form format will result in an error, showing that the received data is all \0 or mostly \0. Setting content-type to application/octet-stream can solve this problem. At this time, the server-side API can parse the data in ordinary binary format. Sample APIs in other languages not contrained to parse data in the form format like the spring framework, but can parse data in ordinary binary format. Other web development frameworks used by java, such as micronaut, can also no need configure content-type. If you can modify the way spring is used to make it parses data in ordinary binary format regardless of the content-type set by the client, you can also achieve the goal. Summary: Configuring content-type is one solution we proposed.There are other solutions as long as the server API can process the uploaded data as normal binary (application/octet-stream).