响应具有无效的HTTP状态码405个AngularJS
我得到这个错误:响应具有无效的HTTP状态码405个AngularJS
的XMLHttpRequest无法加载http://apidev.facu.la/api/json/infotag/search/?criteria=&infotagType=book&companyid=2。当尝试执行此httpget调用时,预检反应的HTTP状态码405无效:
$http({
method: 'GET',
dataType: "json",
url: 'http://apidev.facu.la/api/json/infotag/search/?criteria=&infotagType=book&companyid=2',
headers: {
"Content-Type": "application/json"
}
}).then(function successCallback(response) {
alert('ok');
}, function errorCallback(response) {
alert('error');
console.log(response);
});
任何想法我错过了什么? 邮递员电话工作得很好。 感谢
UPDATE:
端点代码:
[WebInvoke(Method = "GET",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "/json/infotag/search/?criteria={criteria}&infotagType={infotagType}&companyid={companyid}")]
public XElement InfoTagSearchXML_json(string criteria, string infotagType, int companyid)
{
return InfoTagSearchXML(criteria, infotagType, companyid);
}
您可以为方法选项添加WebInvoke到您的ServiceContract这样的:不准
[ServiceContract]
public interface ITestService
{
[WebInvoke(Method = "OPTIONS", UriTemplate = "*")]
void getOptions();
... other invokes
}
public class Service : ITestService
{
public void getOptions()
{
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "GET, OPTIONS");
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Content-Type");
}
... other invokes
}
谢谢@Kronwalled。一旦我补充一点,我如何将它用于我的电话?或者那是我唯一需要做的事情? – Laziale
当您启动GET请求时,应自动调用它 – KRONWALLED
更改后获取此错误https://i.gyazo.com/83267cb7a48c2a1167c015f83b160079.png – Laziale
法(状态代码405)意味着您没有在您的端点上定义任何OPTIONS方法。 CORS请求是强制性的。 请参阅[CORS](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) 您可以提供有关您的端点的任何详细信息吗? (语言,框架等) – KRONWALLED
@Kronwalled只是将问题添加到问题主体。 Thx帮助我! – Laziale