php httpclient cookie,请问如何使用httpclient4,通过cookie传递参数?

涉及业务逻辑的输入是需要通过参数传递的,主要有三种方法:path, query, POST/PUT body

path: GET /api/user/123 其中的123通过path传递

query: GET /api/search_user?userId=123

body: POST /api/user-signup {username: 'john'}

不建议通过header传参的原因:

1. proxy 和 reverse proxy会drop header

2. 不利于传输object

3. HTTP access control (CORS) API 一般会设置Access-Control-Allow-Headers,分分钟教你做人。

4. 不利于dev和debug

5. Header长度限制

然后,如果需要传header,比如Authorization,如下。

jQuery.ajax()

headers (default: {})

Type: PlainObject

An

object of additional header key/value pairs to send along with requests

using the XMLHttpRequest transport. The header X-Requested-With:

XMLHttpRequest is always added, but its default XMLHttpRequest value can

be changed here. Values in the headers setting can also be overwritten

from within the beforeSend function. (version added: 1.5)$.ajax({

url: '/path/to/service',

method: 'GET | POST | PUT | DELETE',

headers: {

'Authorization': 'Bearer ',

'some-other-header': 'some value'

}

})

.done(function(data){...})

.fail(function(jqXHR){...})

.always(function(){...})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值