简体   繁体   English

如何发送宁静的帖子请求?

[英]how to send a restful post request?

I am new to restful web development. 我是宁静的Web开发的新手。 I have tried to search for this but could not find an answer. 我试图搜索此文件,但找不到答案。 In a restful api how do we send data to a post request? 在一个宁静的api中,我们如何将数据发送到发布请求? Is it sent as a query parameter. 是否作为查询参数发送。 Since in a post request the data is sent using the request body using forms. 由于在发布请求中,数据是使用表单通过请求主体发送的。 How do I pass data when developing an API? 开发API时如何传递数据? is it sent as a uri parameter similar to how it happens in get request? 是否作为uri参数发送,类似于在get请求中发生的情况? Can you give an example post request in a rest api. 您能否在rest api中提供示例发布请求。 For example if I want to make a post request to enter data of a student Post /student/new/?name=xys&age=28 Is this valid? 例如,如果我要发布请求以输入学生的数据,则发布/ student / new /?name = xys&age = 28是否有效?

Programming languages/frameworks designed to handle and make web-requests normally give you easy access to the GET or POST parameters OR give you an easy way to pass your POST parameters (all you have to do usually is mention the data as key-value pairs in an object or dictionary and the language/framework will do the work for you). 通常设计用于处理和进行Web请求的编程语言/框架使您能够轻松访问GET或POST参数,或者使您可以轻松地传递POST参数(通常您要做的就是将数据作为键值对提及在对象或字典中,语言/框架将为您完成工作)。

For example, this is a javascript example using jQuery: 例如,这是一个使用jQuery的javascript示例:

$.post("your.api.endpoint.url", { key1:"value1", key2:"value2"});

After making this request, you should be able to open up developer tools in your browser (Ctrl+Shift+I in Chrome) and view the request headers and body and see the key value pairs at the bottom of the request body. 发出此请求后,您应该能够在浏览器中打开开发人员工具(Chrome中为Ctrl + Shift + I),并查看请求标头和正文,并在请求正文底部看到键值对。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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