2016-09-18 7 views
1

これらはhttpヘッダーと認証を持つAlmofireを使用してhttp投稿リクエストを送信するにはどうすればいいですか?

1.parameters URLCredential

let user = "user1" let password = "password1" 

4.URL

let parameters: Parameters = ["username ": "Henry","password":"xxxx","key"="ewq2356"] 

2.httpヘッダ

let headers = [ "Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", "Content-Type": "application/x-www-form-urlencoded" ] 

3.Authentication私の入力であります

http://myapi.com/rest/index.php 

Almofire http postメソッドを使ってどのように使用できますか?

答えて

2

サンプルAPI - >

func someFunction() 
{ 

    Alamofire.request(.POST, "apiName", 
     parameters:["Key":"Value"], 
     headers: ["Content-type application":"json"]) 
     .authenticate(user: "userName", password: "Password") 
     .response { request, response, data, error in 
      if error == nil { 
       print(request) 
       print(response) 
      } 
      else { 
       //Display Error Message 
       print(error) 
      } 

    } 
} 
+0

OK。だから、それは私が言及しているもののURL untenticationにログインを求め、その前に私はヘッダーフィールドでフォームデータ本体とヘッダにパラメータを置くことによって、ポストマンでそれをチェックしていますURLCredential letのユーザー=「USER1」との私の質問の認証にパスワードを聞かせて=「パスワード1」 – Bhagabata

+0

Almofireは言うHTTP基本認証 自動的に適切なURLAuthenticationChallengeにURLCredentialを提供しますリクエストの認証方法: LETユーザー= "あなた"ser" let password = "password" Alamofire.request( "https://httpbin.org/basic-auth/\(user)/\(password)") .authenticate(user:user、password:password) ) .responseJSON { のdebugPrint(応答) } – Bhagabata

+0

そのユーザーとパスワードは、HTTP認証の一部か単純なパラメータですか? –

関連する問題