简体   繁体   English

如何设置REST API调用的Http标头

[英]How to set Http header for an rest api call

I have read some tutorials on REST API development, One thing i could not understand how a single url worked for different HTTP Request methods for example 我已经阅读了一些有关REST API开发的教程,例如,我无法理解单个URL如何用于不同的HTTP Request方法。

GET : api/users/1 GET:api / users / 1
POST: api/users/1 POST:api / users / 1
PUT: api/users/1 放置:api / users / 1

In these cases all urls are same, but action is different. 在这些情况下,所有网址都是相同的,但是操作是不同的。 my question is how a API detect the HTTP request method ?? 我的问题是API如何检测HTTP请求方法? is that HTTP Request method mentioned in url or it can detect automatically?? 网址中提到的HTTP Request方法是它还是可以自动检测? in php 在PHP中

please clarify me.. 请澄清一下

Sorry for my poor English.. 对不起,我英语不好。

thanks in advance.. 提前致谢..

When a request is made, what gets sent is literally "GET www.yahoo.com", for instance. 发出请求时,发送的内容实际上是“ GET www.yahoo.com”。 You can do this in a telnet session, actually. 实际上,您可以在telnet会话中执行此操作。

Literally, Step 1: connect to port 80 of remote server Step 2: send "GET hostname". 从字面上看,步骤1:连接到远程服务器的端口80步骤2:发送“获取主机名”。 Post would be "POST hostname", etc. 发布将是“ POST主机名”,等等。

It quickly gets more complicated with all of the options that can be sent such as cookies, headers, uploads, ssl, etc. But, the verb is always sent in the request. 使用所有可以发送的选项(例如cookie,标头,上载,ssl等),它很快变得更加复杂。但是,动词总是在请求中发送。

If you are asking how to detect in on the server side, there is already a question that answers: PHP detecting request type (GET, POST, PUT or DELETE) 如果您在服务器端询问如何进行检测,那么已经有一个问题可以回答: PHP检测请求类型(GET,POST,PUT或DELETE)

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

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