I have that code that add values to body:
let body = NSMutableData()
let mimetype = "image/jpg"
//define the data post parameter
body.append("--(boundary)
".data(using: String.Encoding.utf8)!)
body.append("Content-Disposition:form-data; name="eventId"
".data(using: String.Encoding.utf8)!)
body.append("(eventId)
".data(using: String.Encoding.utf8)!)
body.append("--(boundary)
".data(using: String.Encoding.utf8)!)
body.append("Content-Disposition:form-data; name="contactId"
".data(using: String.Encoding.utf8)!)
body.append("(contactId)
".data(using: String.Encoding.utf8)!)
body.append("--(boundary)
".data(using: String.Encoding.utf8)!)
body.append("Content-Disposition:form-data; name="type"
".data(using: String.Encoding.utf8)!)
body.append("(type)
".data(using: String.Encoding.utf8)!)
body.append("--(boundary)
".data(using: String.Encoding.utf8)!)
body.append("Content-Disposition:form-data; name="file"; filename="(fileName)"
".data(using: String.Encoding.utf8)!)
body.append("Content-Type: (mimetype)
".data(using: String.Encoding.utf8)!)
body.append(image_data!)
body.append("
".data(using: String.Encoding.utf8)!)
body.append("--(boundary)--
".data(using: String.Encoding.utf8)!)
request.httpBody = body as Data
How to convert it in string? I would like to get the boundary, but impossible to do it.
When I do that, it makes me nil: let test = String(data: body as Data, encoding: .utf8)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…