Main Content

matlab.net.http.RequestMessage class

包裹:matlab.net.http
超类:matlab.net.http.Message

HTTP request message

Description

使用requestMessage班级以格式化HTTP请求消息,以发送到服务器进行处理。使用send发送消息的方法,或completemethod to validate the message before sending. These methods fill in any necessary header fields and other message properties.

Class Attributes

密封
true

有关类属性的信息,请参阅Class Attributes

创建

Description

obj = matlab.net.http.RequestMessage创建具有默认值的请求消息。发送或完成消息时,默认方法property isrequestMethod.get

例子

obj = matlab.net.http.RequestMessage(method,header,body)specifies one or more optional messageproperties。您可以省略拖延论点并使用[]指定任何占位符。

obj = matlab.net.http.RequestMessage(requestLine,header,body)sets therequestLine财产为requestLine。如果需要控制请求行的内容,请使用此语法。例如,要明确将消息发送到代理,请设置requestline.requesttarget属性到完整的URI。否则,MATLAB根据您的代理设置选择代理send方法设置RequestTarget到the小路URI的财产。

obj = matlab.net.http.RequestMessage(requestLine,header,provider)从一个获取消息主体数据matlab.net.http.io.ContentProvider

特性

expand all

请求行,,,,specified as amatlab.net.http.requestline对象,或包含方法,目标和协议版本的字符串或字符向量。当您根据指定的方法和URI发送消息时,将自动创建此行。如果您明确设置此属性,则将其内容用作请求行。该值可能设置为requestLine目的or to a string which is parsed and converted to arequestLine目的。

Example:'获取http/1.1'

一种ttributes:

GetAccess
public
setAccess
public
Dependent
true

Request method, specified as amatlab.net.http.requestmethod枚举or a string or character vector representing a request method. To send a message, set therequestMessage。方法属性或requestline.method财产。

Example:'得到'

一种ttributes:

GetAccess
public
setAccess
public
Dependent
true

消息头,,,,specified as amatlab.net.http.HeaderField对象或向量Headerfield对象。当您设置标题财产,Matlab®checks the fields of the header to ensure that they are appropriate for the message type. TherequestMessagesendandcompletemethods fill in any required header fields for a properly formed request.

一种ttributes:

GetAccess
public
setAccess
public

Message body, specified as amatlab.net.http.messagebody目的,,,,matlab.net.http.io.ContentProvider,,,,or data acceptable to theMessageBodyconstructor. By default,Body是空的(设置为[])。包含一个的请求消息Body属性通常使用诸如'PUT'or'邮政',不是默认值'得到',,,,but this convention is not enforced.

In a completed or received message, if the message has aContentTypefieldheader field, then theMessageBody.ContentTypeproperty is set to that value. Otherwise,ContentType不变或空。

一种ttributes:

GetAccess
public
setAccess
public

消息是否完成,指定为trueor错误的。一种true价值意味着消息已完成。

验证消息的方法(requestMessage。sendandrequestMessage.complete) set theCompleted财产为true后:

  • Determining that the message is valid.

  • Completing processing, such as adding required header fields and converting the data.

如果属性为真,那么这些方法不会修改消息,并且send方法在不检查有效性的情况下发送消息。此后对此消息的任何更改都改变了Completedproperty back to错误的

To send arbitrary headers and data in a request message, setCompletedtrue防止send修改消息的方法。您仍然可以使用complete验证消息的方法,但是sendmethod sends it whether it is valid.

如果请求消息包含数据(Body.Data属性不是空的),然后Completedis set totrueonly ifBody.Payloadcontains the raw data. In a response message, the payload is set only if you specify theHTTPOptions.SavePayload财产。

一种ttributes:

GetAccess
public
setAccess
public
短暂的
true

数据类型:逻辑

消息开始行,指定为matlab.net.http.startline目的。

一种ttributes:

GetAccess
public
setAccess
public

方法s

expand all

Examples

collapse all

Format an HTTP message requesting a server to add text to a website. This example only formats the message and does not send the data.

一种dd content to the message body.

data =“要发送的数据”;body = matlab.net.http.messagebody(data);Body.Show
Data to send

Create a Content-Type header field describing the data type of the body.

contentTypeField = matlab.net.http.field.ContentTypeField(“文字/普通”);

Create an Accept header field specifying the data types acceptable in the response message.

type1 = matlab.net.http.MediaType('text/*');type2 = matlab.net.http.mediatype('应用程序/json',,,,'Q',,,,'.5');acceptfield = matlab.net.http.field.acceptfield([type1 type2]);

创建一个包含两个标头字段的请求标题。

header = [acceptfield contentTypefield];

指定此消息是一个PUT请求。

method = matlab.net.http.RequestMethod.PUT;

创建请求消息并显示内容。

请求= matlab.net.http.RequestMessage(方法,标头,车身);显示(请求)
PUT Accept: text/*, application/json; q=.5 Content-Type: text/plain Data to send
在R2016b中引入