gpt4 book ai didi

json - Swift Alamofire 发布请求不起作用,

转载 作者:行者123 更新时间:2023-11-30 13:49:09 25 4
gpt4 key购买 nike

我正在尝试通过 Alamofire 发送简单的 http post 请求。我需要用户名和密码,请求正文是 json 格式。首先我不确定我的代码是否正确(Apple开发者的初学者。)其次,每次我兴奋代码时我都会感到困惑,它根本没有进入responseJSON block 。有人可以给我提示吗,谢谢这是我的代码

func sendTestResult(result: Int, testrun: Int, testcaseindex: Int) -> Bool{
var resp : Bool = false;

//add testcase info
var url: String = self.testrailsUrl + "/\(testrun)/\(testcaseindex)"
//add authentication info
// url = testrailsUrl + "/basic-auth/\(self.testrailsUserName)/\(self.testrailsPassword)"

assert(url == "http://ypdine.testrail.net/index.php?/api/v2/add_result_for_case/4/3",
"the post information isn't right")

let parameters = ["status_id": [result]]
print("here sending the request")
Alamofire.request(.POST, url, parameters: parameters, encoding: .JSON)
.authenticate(user: self.testrailsUserName, password: self.testrailsPassword)
.validate(statusCode: 200..<300)
.responseJSON { response in
print(response.request) // original URL request
print(response.response) // URL response
print(response.data) // server data
print(response.result) // result of response serialization

if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}

return resp
}

最佳答案

尝试从函数中删除“-> Bool”和“return resp”,以便 Alamofire 有机会响应。

关于json - Swift Alamofire 发布请求不起作用,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34533096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com