私はPOSTMANで投稿要求をするときに問題はありませんが、私はalamofireを使用するときに問題があります。ポストはまだalamofireの要求を通過しますが、データは同じ方法で受信されません。 alamofire要求が...それは、次の郵便配達とまったく同じだように何を見てんAlamofireへの郵便要求依頼
0
A
答えて
0
スウィフト2.xの:
typealias apiSuccess = (result: NSDictionary?) -> Void
typealias apiProgress = (result: NSDictionary?) -> Void // when you want to download or upload using Alamofire..
typealias apiFailure = (error: NSDictionary?) -> Void
// Normal http request with JSON response..
func callJSONrequest(url:String, params:[String: AnyObject]?, success successBlock :apiSuccess,
failure failureBlock :apiFailure) {
Alamofire.request(.POST, url, parameters: params, encoding: ParameterEncoding.URL)
.responseJSON { response in
print("\(response.request?.URL)") // original URL request
//print(response.response) // URL response
//print(response.data) // server data
//print(response.result) // result of response serialization
if response.result.isSuccess {
let jsonDic = response.result.value as! NSDictionary
successBlock(result: jsonDic)
} else {
let httpError: NSError = response.result.error!
let statusCode = httpError.code
let error:NSDictionary = ["error" : httpError,"statusCode" : statusCode]
failureBlock(error: error)
}
}
}
func myFunction() {
let myApiSuccess: apiSuccess = {(result: NSDictionary?) -> Void in
print ("Api Success : result is:\n \(result)")
// Here you can make whatever you want with result dictionary
}
let myApiFailure: apiFailure = {(error: NSDictionary?) -> Void in
print ("Api Failure : error is:\n \(error)")
// Here you can check the errors with error dictionary looking for http error type or http status code
}
var params :[String: AnyObject]?
let email : String! = "[email protected]"
let password : String! = "thisismypassword"
params = ["email" : email, "password" : password]
let url : String! = "https://arcane-brook-75067.herokuapp.com/login"
callJSONrequest(url, params: params, success: myApiSuccess, failure: myApiFailure)
}
+0
こんにちは私はこの作業をしようとしています。下の関数でエラーが出ます。まず、関数の最初の括弧の後にカンマがあるのです...私は 'let myApiSuccessとmyApiFailureのそれぞれで未使用関数に解決されます。 – user1990406
+0
私の個人レポからコピー&ペースト中におそらくいくつかの間違い..待って.. –
+0
いいえ、今すぐ試してください、コンマと2つの括弧があります。 –
関連する問題
- 1. 郵便配達要求チェーン
- 2. 郵便配達要求
- 3. カールからの郵便配達要求
- 4. 郵便配達人の要求をチェーンする - 別の要求からの郵便配達人の要求を呼び出すか?
- 5. 郵便はがきの身体の要求
- 6. 紺碧400不正な要求は郵便配達
- 7. 郵便番号への経度/緯度?
- 8. 郵便受けの主要なソースコードリポジトリ?
- 9. 郵便は、カスタムヘッダー
- 10. 郵便番号
- 11. 郵便番号
- 12. 郵便配達
- 13. AlamofireのJSON要求スウィフト3
- 14. のpythonと要求動作しませんが、郵便配達の仕事
- 15. 着信要求の郵便番号を追跡するためのDropwizardメトリック
- 16. 郵便配達を使用してSparkJavaの作業を実行しているローカルホストサーバーへの要求が、ブラウザ
- 17. 郵便配達人の要求から起点ヘッダーを削除する
- 18. 400不正な要求:「あなたの要求を完了できませんでした」 - 郵便配達
- 19. Alamofire SWIFT 3.1郵便サービスコールの応答以下の私のコードは、文字列=
- 20. Alamofire要求はキャンセルされ
- 21. Alamofire 3.5.1は、アップロード要求
- 22. ASP.NET Core APIコールによる郵便配達要求が不正です
- 23. 郵便番号が
- 24. Django:郵便番号
- 25. 郵便配達員と並行依頼するにはどうすればよいですか?
- 26. geoip郵便番号のクエリ
- 27. Javaの郵便住所パーサー
- 28. 郵便番号の質問
- 29. 郵便配達:前提スクリプトの郵便配達要求のURLを更新することは可能ですか?
- 30. 特定の郵便番号の最も近い郵便番号の検索
あなたはいくつかのコードを投稿することができますか? –