0
私は誰かがPOSTリクエスト(パラメータ付き)が達成するものを説明できることを望んでいました。私はAlamofireのドキュメントが提供する次のコマンドを実行すると、これが生産されているものです:パラメータやPOSTリクエストで発生している正確に何Alamofire POST Request
コード
let url = "https://httpbin.org/post"
let parameters: Parameters = [
"foo": "bar",
"baz": ["a", 1],
"qux": [
"x": 1,
"y": 2,
"z": 3
]
]
Alamofire.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default).responseJSON { response in
if((response.result.value) != nil) {
let jsonVar: JSON = JSON(response.result.value!)
print(jsonVar)
}
}
結果
{
"files" : {
},
"origin" : "192.104.181.247",
"data" : "{\"baz\":[\"a\",1],\"qux\" {\"y\":2,\"x\":1,\"z\":3},\"foo\":\"bar\"}",
"headers" : {
"Accept" : "*\/*",
"Accept-Encoding" : "gzip;q=1.0, compress;q=0.5",
"Content-Type" : "application\/json",
"Host" : "httpbin.org",
"Content-Length" : "53",
"User-Agent" : "HTTPRequest\/1.0 (com.dexstrum.HTTPRequest; build:1; iOS 10.2.0) Alamofire\/4.3.0",
"Accept-Language" : "en;q=1.0"
},
"json" : {
"baz" : [
"a",
1
],
"foo" : "bar",
"qux" : {
"x" : 1,
"y" : 2,
"z" : 3
}
},
"form" : {
},
"args" : {
},
"url" : "https:\/\/httpbin.org\/post"
}
?
これは助けになりました。私のパラメータが間違っていたり間違って渡されているかもしれないことに気付きました。 – Dexstrum
私が作成したパラメータが正しく渡されていないのはなぜかと思います。パラメータ:["x":2、 "y":2]、これは私のポストコードAlamofire.request(url、メソッド:.post、parameters:parameters、encoding:JSONEncoding.default).responseJSON { に応答するif(!(response.result.value)= NIL){ jsonVarましょう:JSONは= JSON(!response.result.value) プリント(jsonVar) }他{ プリント(response.result.value ? "no response") } } – Dexstrum
これは応答なしの結果を生成しています。 – Dexstrum