21
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AlamofireでPOSTする

Last updated at Posted at 2017-11-24

#学んだ事
Alamofireを使ってAPI通信

##ソースコード

signupViewController.swift
func HttpRequest() {
        let url = "URLをいれてね"
        let headers: HTTPHeaders = [ 
            "Contenttype": "application/json"
        ]
        let parameters:[String: Any] = [
            "username": username,
            "password": password
        ]

        Alamofire.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers).responseJSON { response in
            if let result = response.result.value as? [String: Any] {
                print(result)
            }
        }

    }

自分はこれを使いたいタイミングで関数を呼び出して使ってます
POSTしたい内容をparametersに書いて投げてるんだと思います
http通信についての知識が皆無なためいい本とかあれば教えて欲しいです

21
14
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?