ログインする必要のあるサイトをhtmlで取ってくるのにalamofireでbasic認証しようと思い、
以下のコードを書きましたが、Extra argument in callというエラーがAlamofire.request(.GET, "https://localhost.jp/basic-auth/")の引数のURLに対して出ます。
何が悪いのかよくわかりません。よろしくお願いいたします。
swift
1Alamofire.request(.GET, "https://localhost.jp/basic-auth/") 2 .authenticate(user: user, password: password) 3 .response {(request, response, _, error) in 4 print(response) 5 }
コード全文
swift
1// 2// ViewController.swift 3// url3 4// 5// Created by 東愛央衣 on 2017/11/21. 6// Copyright © 2017年 東愛央衣. All rights reserved. 7// 8 9import UIKit 10import Alamofire 11 12var days: Int = 0 13let weekArray = [" ", "月", "火", "水", "木", "金", "土"] 14let subjectArray = ["1", "月", "火", "水", "木", "金", "土", 15 "2", "月", "火", "水", "木", "金", "土", 16 "3", "月", "火", "水", "木", "金", "土", 17 "4", "月", "火", "水", "木", "金", "土", 18 "5", "月", "火", "水", "木", "金", "土", 19 "6", "月", "火", "水", "木", "金", "土", 20 "7", "月", "火", "水", "木", "金", "土"] 21 22let user = "blueeeast@keio.jp" 23let password = "B1UEast9280" 24 25 26 27 28class ViewController: UIViewController,UICollectionViewDataSource { 29 30 31 func numberOfSections(in collectionView: UICollectionView) -> Int { 32 return 2 33 } 34 35 36 37 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 38 if section == 0{ 39 return 7 40 } else { 41 return 49 42 43 } 44 } 45 46 47 48 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 49 //コレクションビューから識別子「TestCell」のセルを取得する。 50 let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TestCell", for: indexPath) as! TestCollectionViewCell 51 if indexPath.section == 0 { 52 cell.backgroundColor = UIColor.gray 53 cell.testLabel.text = weekArray[indexPath.row] 54 } else { 55 cell.backgroundColor = UIColor.white 56 cell.testLabel.text = subjectArray[indexPath.row] 57 } 58 return cell 59 } 60 61 62 63 override func viewDidLoad() { 64 super.viewDidLoad() 65 // Do any additional setup after loading the view, typically from a nib. 66 let client = Client() 67 client.authenticate(user: user, password: password) 68 } 69 70 override func didReceiveMemoryWarning() { 71 super.didReceiveMemoryWarning() 72 // Dispose of any resources that can be recreated. 73 } 74 class Client { 75 76 77 78 79 80 public func authenticate(user: String, password: String) -> Self { 81 82 83 84 85 Alamofire.request(.GET, "https://localhost.jp/basic-auth/") 86 .authenticate(user: user, password: password) 87 .response {(request, response, _, error) in 88 print(response) 89 } 90 91 // var webContext:NSString! = nil 92 // //ダウンロード 93 // let url = URL(string: "https://www.edu.keio.jp/ess2/login?lang=jp")! 94 // let task = URLSession.shared.dataTask(with: url) { data, response, error in 95 // if let jsonData = data { 96 // print(jsonData) 97 // 98 // 99 // webContext = NSString(data:jsonData,encoding:String.Encoding.utf8.rawValue) 100 // print(webContext) 101 // 102 // } 103 // } 104 // task.resume() 105 // } 106 107 } 108 } 109} 110 111 112
そのエラーはどの行に対して出ていますか?エラーの文面だけ見ると、「余計な引数がある」という意味です。
回答1件
あなたの回答
tips
プレビュー