I am trying to do a post request and send a message with mailgun API, but I can't seem to figure out how to format the message data in swift. Having issues with from parameter in the data I am uploading.
request.setValue("Basic \(base64Credentials)", forHTTPHeaderField: "Authorization")
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
let data = "from: Foo <info@sandbox(sandboxInfo).mailgun.org>&to: <foo@me.com>&subject:Hello&text:Testing Mailgun"
request.httpBody = data.data(using: String.Encoding.ascii)
Respone:
);
"Cache-Control" = (
"no-store"
);
Connection = (
"keep-alive"
);
"Content-Length" = (
46
);
"Content-Type" = (
"application/json"
);
Date = (
"Wed, 03 Mar 2021 01:05:39 GMT"
);
Server = (
nginx
);
} }
response code = 400
data {
"message": "'from' parameter is missing"
}