我创建网络API来提供像PIN码,银行IFSC代码等服务,从为http://www.ajaxserver.com
如何知道客户端的URL名称?
我所有的API是在我的网站和我所有的客户端访问使用我的网站托管我的网站命名。 网页API代码
[Route("api/GetURLName/")]
[HttpGet]
public string GetURLName(HttpRequestMessage request)
{
return HttpContext.Current.Request.Url.AbsoluteUri ;
}
我的一个客户网站的名字是http://www.clientwebsite.online
客户端使用jQuery来检索像下面的代码信息。
$('#btnTestCore').click(function() {
$.ajax({
url: 'http://ajaxserver.com/api/GetURLName/',
dataType: 'json',
type: 'GET',
contentType: "application/json; charset=utf-8",
success: function (data) {
alert(data);
},
error: function (data) {
alert('failed.');
}
});
});
输出谈到:
"http://ajaxserver.com/api/GetURLName/".
需要输出:
"http://clientwebsite.online/api/GetURLName/"
你看到的是预期的行为,你是返回请求url(这是你的网站)。你有没有尝试RequestReferrer – Shyju
我调整了网址,以避免看起来垃圾邮件 –
无法使用RequestReferrer,显示运行时错误... –