m子4 encodeuri函数不逃脱
我必须执行Microsoft Dynamics 365 CRM URL。该请求具有一个名为SELECT的查询参数,并且查询参数的值如下如
咨询ID,专家,科学家,host_value,numberFdaysSpentConsultingAnnualSurvey,dateOfSurvey&$ explavey&explive&explive&expliant = scientist($ selecteemist($ selecteee =雇员),
我在dataweave中使用了dataweave的功能,价值具有& $等
<http:request method="GET" config-ref="Dynamics365_CRM_Request_Configuration" path="${dynamics365.crm.http.path}" doc:name="Request" doc:id="903e22c5-47c0-47bd-9faa-c87d217bf856" >
<http:headers ><![CDATA[#[import * from dw::core::URL
output application/java
---
{
"Authorization" : "Bearer " ++ vars.bearerToken,
"Prefer": "odata.maxpagesize=250, odata.include-annotations=OData.Community.Display.V1.FormattedValue",
"Content-Type" : "application/json"
}]]]></http:headers>
<http:query-params ><![CDATA[#[import * from dw::core::URL
output application/java
---
{
"\$select" : encodeURI(vars.dynamicsUrl)
}]]]></http:query-params>
</http:request>
我提交时,我会得到答复 语法错误:字符'&amp;'无效 我看到&amp;正确地编码了%26,如下片段,
%2Cdateofsurvey%26%24expand%3Dsage_scientist%28%24select%3Demployeeid%29
任何帮助都将不胜感激。
I have to perform a GET Request a Microsoft Dynamics 365 CRM URL. The request has one query parameter called select and the value of the query param is as below
consultingid,expert,scientist,host_value,numberofdaysspentconsultingannualsurvey,dateofsurvey&$expand=scientist($select=employeeid)
I am using the encodeURI function in Dataweave as below as the value has & $ etc
<http:request method="GET" config-ref="Dynamics365_CRM_Request_Configuration" path="${dynamics365.crm.http.path}" doc:name="Request" doc:id="903e22c5-47c0-47bd-9faa-c87d217bf856" >
<http:headers ><![CDATA[#[import * from dw::core::URL
output application/java
---
{
"Authorization" : "Bearer " ++ vars.bearerToken,
"Prefer": "odata.maxpagesize=250, odata.include-annotations=OData.Community.Display.V1.FormattedValue",
"Content-Type" : "application/json"
}]]]></http:headers>
<http:query-params ><![CDATA[#[import * from dw::core::URL
output application/java
---
{
"\$select" : encodeURI(vars.dynamicsUrl)
}]]]></http:query-params>
</http:request>
When I submit I am getting a response saying
Syntax error: character '&' is not valid
I see that the & is correctly encoded with %26 as below fragment
%2Cdateofsurvey%26%24expand%3Dsage_scientist%28%24select%3Demployeeid%29
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用
encodeuricomponent
。encodeuri
用于创建整体有效的URL。它不会编码URL中允许的字符,例如“&amp;”。所以Encodeuri不会编码:〜!@#$&amp;*()=:/,;?+'
encodeuricomponent
用于获取可以在URI(URI)中使用的字符串,因此它将编码所有具有特殊含义的URI的内容。它是针对JS的,但这个概念是相同的
You need to use
encodeURIComponent
.encodeURI
is used to create an overall valid URL. It will not encode the characters that are allowed in a URL, for example "&". ThereforeencodeURI will not encode: ~!@#$&*()=:/,;?+'
encodeURIComponent
is used to get a string that you can use inside a URI (component of URI) so it will encode everything that has a special meaning for a URIYou can refer to this question for more details. It is for JS but the concept is same