나는 경로가있는 HttpPOST .Net WebApi를 가지고 있습니다 : http://blah/api/CarValues?userId=1&carId=5&value=12.12
. 이 webApi는 Azure에 게시되어 있으며 Postman을 통해 호출 할 수 있습니다.Swift에서 HttpPost Web API를 실행할 수 없습니다.
responseString = Optional("{\"Message\":\"No HTTP resource was found that matches the request URI \'http://blah.net/api/CarValues\'.\"}")
내 현재 코드입니다 : 내가 왜 확인
func postCarInfo() {
// Posts to cloud
var request = URLRequest(url: URL(string: webApiUrl)!)
request.httpMethod = "POST"
let postString = "userId=1&carId=5&value=200.00"
request.httpBody = postString.data(using: .utf8)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data, error == nil else { // check for fundamental networking error
print("error=\(error)")
return
}
if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 { // check for http errors
print("statusCode should be 200, but is \(httpStatus.statusCode)")
print("response = \(response)")
}
let responseString = String(data: data, encoding: .utf8)
print("responseString = \(responseString)")
}
task.resume()
}
아니에요 내가이 엔드 포인트에 데이터를 게시하려고 할 때, 내 빠른 응용 프로그램의 내부에, 나는이 얻을 이 작동하지 않습니다. 포스트 맨을 통해이 엔드 포인트를 여러 번 성공적으로 시도해 보았습니다. 포스트가 아닌 다른 webApi 메소드에 액세스 할 수 있습니다. 또한 NSAppTransportSecurity
을 NSAllowsArbitraryLoads
허용하도록 설정했지만 여전히 엔드 포인트에 액세스 할 수 없습니다.
이 어떤 도움을 크게 어쩌면이 관련되어