docs/docsets/Alamofire.docset/Contents/Resources/Documents/Classes/StringResponseSerializer.html
public final class StringResponseSerializer : ResponseSerializer
A ResponseSerializer that decodes the response data as a String. By default, a request returning nil or no data is considered an error. However, if the request has an HTTPMethod or the response has an HTTP status code valid for empty responses, then an empty String is returned.
`
dataPreprocessor
`
Swift
public let dataPreprocessor: any DataPreprocessor
`
encoding
`
Optional string encoding used to validate the response.
Swift
public let encoding: String.Encoding?
`
emptyResponseCodes
`
Swift
public let emptyResponseCodes: Set<Int>
`
emptyRequestMethods
`
Swift
public let emptyRequestMethods: Set<HTTPMethod>
`
init(dataPreprocessor:encoding:emptyResponseCodes:emptyRequestMethods:)
`
Creates an instance with the provided values.
Swift
public init(dataPreprocessor: any DataPreprocessor = StringResponseSerializer.defaultDataPreprocessor,
encoding: String.Encoding? = nil,
emptyResponseCodes: Set<Int> = StringResponseSerializer.defaultEmptyResponseCodes,
emptyRequestMethods: Set<HTTPMethod> = StringResponseSerializer.defaultEmptyRequestMethods)
| dataPreprocessor |
DataPreprocessor used to prepare the received Data for serialization.
|
| encoding |
A string encoding. Defaults to nil, in which case the encoding will be determined from the server response, falling back to the default HTTP character set, ISO-8859-1.
|
| emptyResponseCodes |
The HTTP response codes for which empty responses are allowed. [204, 205] by default.
|
| emptyRequestMethods |
The HTTP request methods for which empty responses are allowed. [.head] by default.
|
`
serialize(request:response:data:error:)
`
Swift
public func serialize(request: URLRequest?, response: HTTPURLResponse?, data: Data?, error: (any Error)?) throws -> String