Friday, October 9, 2026
HomeiOS Developmentios - URLSessionDataTask - add parameters with multipart/form-data content material sort

ios – URLSessionDataTask – add parameters with multipart/form-data content material sort

[ad_1]

I wish to create physique like on this curl instance:

curl --location --request POST 'https://request.url' 
--header 'Authorization: Bearer xxx' 
--form 'title="Title"' 
--form 'information="[{"text": "This is comment", "another": "Thomas"}]"'

How can I implement this and accurately set httpBody in URLRequest?

I attempted completely different approaches however nothing appears to work. Easy:

let physique = NSMutableData()
physique.appendString("title=" request.title))
physique.appendString("information=" + "[{"text": "This is comment", "another": "Thomas" }]"))
return Information(physique)

Then I attempted to prepand: "Content material-Disposition: form-data;". Or added line breakers. Nothing appears to be working.

That strains of code are a part of class that helps me work with requests. What is the easiest approach to get it working? Thanks for assist

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments