我試圖通過Dynamics CRM 2016 Web API使用搜索功能(https://msdn.microsoft.com/en-us/library/mt608029.aspx)。這是我的代碼:Dynamics CRM Web Api功能:使用encodeURIComponent時路徑中的非法字符
var start = new Date(2016, 2, 1, 17, 0, 0);
var end = new Date(2016, 2, 10, 18, 0, 0);
var request = new Object();
request.AppointmentRequest = new Object();
request.AppointmentRequest.SearchWindowStart = start.toISOString();
request.AppointmentRequest.SearchWindowEnd = end.toISOString();
request.AppointmentRequest.ServiceId = "5f3b6e7f-48c0-e511-80d7-d89d67631c44";
request.AppointmentRequest.Direction = 0;
request.AppointmentRequest.NumberOfResults = 10;
request.AppointmentRequest.UserTimeZone = 1;
var req = new XMLHttpRequest()
req.open("GET", clientUrl + "/api/data/v8.0/Search(" + encodeURIComponent(JSON.stringify(request)) +")", true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function() {
if (req.readyState == 4 && req.status == 200) {
alert(req.responseText);
}
else {
alert(req.response);
}
};
req.send();
當我最初嘗試這種使用CRM在線我收到以下錯誤:
"An error has occurred.
Try this action again. If the problem continues, check the Microsoft Dynamics >CRM Community for solutions or contact your organization's Microsoft >Dynamics CRM Administrator. Finally, you can contact Microsoft Support."
當我嘗試這與現場部署與DevErrors =「開」 web.config中,我看到在事件查看器中出現以下錯誤:
Exception information: Exception type: HttpException Exception message: A potentially dangerous Request.Path value was detected >from the client (:). at System.Web.HttpRequest.ValidateInputIfRequiredByConfig() at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext >context)
Request information: Request URL: http://win-0e5dfqgqorm:444/ORG/api/data/v8.0/Search ({"AppointmentRequest":{"SearchWindowStart":"2016-03-01T17:00:00.000Z","SearchWindowEnd":"2016-03-10T18:00:00.000Z","ServiceId":"5f3b6e7f-48c0-e511-80d7-d89d67631c44","Direction":0,"NumberOfResults":10,"UserTimeZone":1}}) Request path: /SHUDEV/api/data/v8.0/Search({"AppointmentRequest":{"SearchWindowStart":"2016-03-01T17:00:00.000Z","SearchWindowEnd":"2016-03-10T18:00:00.000Z","ServiceId":"5f3b6e7f-48c0-e511-80d7-d89d67631c44","Direction":0,"NumberOfResults":10,"UserTimeZone":1}})
JSON對象進行編碼,所以我不知道爲什麼它檢測到非法字符。 Web Api的SDK文檔很簡單,並沒有涉及如何將ComplexType傳遞給Web Api函數的詳細信息,有沒有人在/將ManageType傳遞給Web Api函數之前看到過這個問題?
在此先感謝。