是否有一种简单的方法可以在身体中发送Alamofire中的键值,而不是参数?

时间:2017-02-14 02:50:19

标签: swift alamofire

我需要在正文中的密钥下发送字符串列表。 Alamofire使参数变得非常简单,但我无法弄清楚如何在请求体内完成它。这对我来说不起作用,因为它是一个简单的字符串,我无法弄清楚如何使它适用于一串字符串:POST request with a simple string in body with Alamofire。这个标题是关于JSON主体,但答案是将它们作为参数Alamofire 4, Swift 3 and building a json body给出。有没有人有答案或链接到实际解决我的问题的东西?

所要求的代码:

var params = ["phone_numbers": [6314560046, 8458200476]] as [String: Any]

Alamofire.request(url, method: .post, parameters: params, encoding: JSONEncoding.default, headers: headers).responseJSON() { response in

1 个答案:

答案 0 :(得分:0)

使用Alamofire,参数是请求的主体。这将创建具有字符串数组值的键:

var played:Boolean;

var mySound:Sound;
var myChannel:SoundChannel

// That will be executed only once, because the
// next time this variable will be initialized.
if (mySound == null)
{
    played = true;

    var soundFile:URLRequest = new URLRequest("music.mp3");

    mySound = new Sound;
    mySound.load(soundFile);
    myChannel = new SoundChannel;
    myChannel = mySound.play(0,999);

    pause_btn.addEventListener(MouseEvent.CLICK,pauseSound);
}

然后在发出请求时使用参数:

let parameters = ["Key": ["String1", "String2", "String3"]]