m子4 encodeuri函数不逃脱

发布于 2025-02-05 20:36:51 字数 1312 浏览 4 评论 0原文

我必须执行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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝海 2025-02-12 20:36:52

您需要使用 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 "&". Therefore
encodeURI 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 URI

You can refer to this question for more details. It is for JS but the concept is same

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文