當我通過這個請求時,它傳遞null來請求服務器站點上的參數。 數據屬性有問題嗎?參數在Jsonp請求中傳遞null
$.getJSON('http://127.0.0.1:81/api/sites/GetDomainAvailability?apikey=asfasfdsf&callback=?', { "request": '{"SubDomain":"asfsadf","ParentDomain":"asfasdf","ResellerId":"asfdsd"}' }, function (results) {
alert('Cross domain JS call achieved. Have your implementation going in here!');
});
API C#
[HttpGet]
public HttpResponseMessage GetDomainAvailability(GetDomainAvailabilityRequest request)
{
if (ModelState.IsValid)
{
if (request == null) return Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid Request");
var domain = string.Format("{0}.{1}", request.SubDomain, request.ParentDomain);
var manager = new CloudSitesManager();
var isDomainAvailable = manager.GetDomainAvailability(domain);
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, isDomainAvailable);
return response;
}
else
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
}
[Serializable]
public class GetDomainAvailabilityRequest
{
public string SubDomain { get; set; }
public string ParentDomain { get; set; }
public string ResellerId { get; set; }
}
測試了這一點,但沒有benifit ..我注意到,而不是完整的對象,如果我改變api代碼接受三個參數,然後它的工作.. public HttpResponseMessage GetDomainAvailability字符串subDomain,字符串parentDomain,字符串resellerId) ________ >>>> {subDomain:subDomain,parentDomain:parentDomain,resellerId:resellerId} –
因此問題與完整的對象。 –
試試我的編輯。如果這仍然無效,請嘗試將.getJSON更改爲$ .post()。 –