帮助中心帮助中心
类: matlab.net.http.Message 命名空间: matlab.net.http
在消息标头中添加字段
msg = addFields(msg,fields)
msg = addFields(msg,fName,fValue)
msg = addFields(msg,fName1,fValue1,...,fNameN,fValueN)
msg = addFields(msg,index,___)
示例
msg = addFields(msg,fields) 在每个消息标头的末尾添加 fields 并返回更新后的消息。
msg
fields
addFields 不会检查重复字段,但 RequestMessage send 和 complete 方法可能会拒绝不正确的重复项。
addFields
RequestMessage
send
complete
要防止 send 或 complete 方法自动添加某个特定的标头字段,请使用空 ([]) Value 属性为该字段调用 addFields。
[]
Value
msg = addFields(msg,fName,fValue) 添加名称为 fName、值为 fValue 的字段。
fName
fValue
msg = addFields(msg,fName1,fValue1,...,fNameN,fValueN) 按指定的顺序添加由 fName 和 fValue 对组参量指定的字段。
msg = addFields(msg,index,___) 在 index 处插入字段,且可包含上述语法中的任何输入参量。
index
全部展开
matlab.net.http.Message
消息,指定为 matlab.net.http.Message 对象。
matlab.net.http.HeaderField
要添加的字段,指定为向量或由一个或多个 matlab.net.http.HeaderField 对象组成的逗号分隔列表。
示例: matlab.net.http.HeaderField('Accept','text/plain')
matlab.net.http.HeaderField('Accept','text/plain')
标头字段名称,指定为字符串。
示例: 'Accept'
'Accept'
标头字段值,指定为字符串或对 fName 有效的任何类型。要使用此字段的默认值,请将 fValue 设置为 ''。如果最后一个值缺失,则相当于指定 []。
''
示例: 'text/plain'
'text/plain'
消息标头中的位置,指定为整数。如果 index 大于标头的长度或者 index 为 0,此方法将在末尾添加字段。如果 index 为负数,此方法将从标头的末尾算起。
示例: -1 将在最后一个字段前面插入 fields
-1
创建一个值为 'text/plain' 的 Accept 标头字段,并将其添加到默认请求消息中。
field = matlab.net.http.HeaderField('Accept','text/plain'); m = matlab.net.http.RequestMessage('get'); msg = addFields(m,field); show(msg)
GET Accept: text/plain
在请求消息中添加两个标头字段。
m = matlab.net.http.RequestMessage('get'); msg = addFields(m,'Accept','text/plain','Cache-Control','no-store, no-cache'); show(msg)
GET Accept: text/plain Cache-Control: no-store, no-cache
创建具有两个标头字段的请求消息。
m = matlab.net.http.RequestMessage('get'); msg = addFields(m,'Accept','text/plain','Cache-Control','no-store, no-cache');
在消息中的最后一个标头字段之前插入一个 Content-Type 标头字段。
f = matlab.net.http.HeaderField('Content-Type','text/plain'); msg = addFields(msg,-1,f); show(msg)
GET Accept: text/plain Content-Type: text/plain Cache-Control: no-store, no-cache
在 R2016b 中推出
matlab.net.http.HeaderField | matlab.net.http.RequestMessage
matlab.net.http.RequestMessage
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office