我在此网址中有一个非常简单的POST API:https://lookaguide.com/api/test
api在Laravel 5.2中,这个api只返回一个字符串,上面写着:“一切都好”
这是API的代码:
Route::post('test', function(){
return response()->json(['All is OK']);
});
当我将这个API与Postman一起使用时,api会返回正确的信息。
我正在使用Alamofire 3.4,当我使用API时,405错误出现就像POST resquest不存在一样。
这是我的代码:
Alamofire.request(.POST, "https://lookaguide.com/api/test", parameters: nil)
.responseJSON { response in
switch response.result {
case .Success:
print(response.request) // original URL request
print(response.response) // URL response
case .Failure(let error):
print(response.request) // original URL request
print(response.response) // URL response
}
}
打印respose.response
时Xcode出错 Optional(<NSHTTPURLResponse: 0x7914a870> { URL: https://lookaguide.com/api/test } {
status code: 405, headers {
"Cache-Control" = "no-cache, private";
Connection = "Keep-Alive";
"Content-Type" = "text/html; charset=UTF-8";
Date = "Wed, 03 Aug 2016 18:24:49 GMT";
"Keep-Alive" = "timeout=3, max=30";
Server = "Apache Phusion_Passenger/4.0.10 mod_bwlimited/1.4 mod_fcgid/2.3.9";
"Transfer-Encoding" = Identity;
"X-Powered-By" = "PHP/5.6.22";
allow = POST;
} })
有什么建议吗?