问题
I'm trying to call an RESTful API within BizTalk. I need to make a GET against the following endpoint:
https://mycompany.com/buyer/sandboxevol/
I have below mappings configured in my Send Port
<BtsHttpUrlMapping>
<Operation Name='Operation_1' Method='GET' Url='/page.aspx/en/eai/api/supplier/{id}?apikey={apikey}&format={format}' />
</BtsHttpUrlMapping>
paramater apikey has value as XXXXXXXXXXzvrpZHbMdKY75zbszhGOu%2bfnmP7Ms%3d. I have checked this and verified from suspended instance. But error message different apikey value present. Refer screenshot Error message (hkey value highlighted)
character % is being encoded as %25 in error message. I believe there are 2 issues
- Invalid APi key issue (this post talks about this) and
- Some firewall/proxy opening between BizTalk and 3rd party system (I shall check this with internal Admin team)
Any thoughts on resolving this encoding/weird issue
回答1:
Based on the error, its most likely happening due to TLS version mismatch. BizTalk 2013 by default use TLS1.0. The recommended version now is to use TLS1.2 or up. You can check with API provider which version of TLS they use. You can change BizTalk behavior by creating a custom send pipeline component and then set TLS version using following code in Execute method. There is no change required to BizTalk message in pipeline component, just place this one line code and return same pInMsg from execute method.
System.Net.SecurityPointManager.SecurityProtocol = SecurityProtocolType.Tls12
ref like Microsoft doc
You can also use external tools such as Postman, Fiddler to test API calls outside BizTalk to make sure API works outside BizTalk.
public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
{
System.Net.SecurityProtocolType protocolType;
if (!String.IsNullOrEmpty(TlsVersion)
&& Enum.TryParse<System.Net.SecurityProtocolType>(TlsVersion, true, out protocolType))
System.Net.ServicePointManager.SecurityProtocol = protocolType;
else
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
return pInMsg;
}
来源:https://stackoverflow.com/questions/62590234/encoding-issue-when-passing-url-parameters-with-biztalk-wcf-webhttp-send-port