gpt4 book ai didi

c# - 无法将数据发布到 UAT 服务器中的 Salesforce

转载 作者:太空宇宙 更新时间:2023-11-03 14:39:28 24 4
gpt4 key购买 nike

我已经创建了一个 api 请求来发布表单数据以在 salesforce 中创建潜在客户。

首先我请求授权 key 将数据插入 salesforce(使用 oauth、客户端 ID 和客户端密码。)

这在本地有效,并且数据已成功发布到 salesforce 中。接下来,我将此代码移至 UAT 服务器。在该 UAT 服务器中,我无法获得授权 key ,并且数据未发布到 salesforce

下面我附上了日志文件中的错误

 //Function to Get Authorization
public static string GetAuthorizationKey(ApiAuthorizeModel apiAuthorizeModel)
{
try
{
string jsonResponse = string.Empty;
string AuthToken = string.Empty;
string Error = string.Empty;
string ErrorDescription = string.Empty;

if (!string.IsNullOrEmpty(apiAuthorizeModel.ClientID) && !string.IsNullOrEmpty(apiAuthorizeModel.ClientSecret) && !string.IsNullOrEmpty(apiAuthorizeModel.UserName) && !string.IsNullOrEmpty(apiAuthorizeModel.Password) && !string.IsNullOrEmpty(apiAuthorizeModel.TokenURI))
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
using (var client = new HttpClient())
{
var request = new FormUrlEncodedContent(new Dictionary<string, string>{
{ApiConstants.Grant_type, ApiConstants.Password},
{ApiConstants.Client_key,apiAuthorizeModel.ClientID},
{ApiConstants.Client_secret, apiAuthorizeModel.ClientSecret},
{ApiConstants.Username, apiAuthorizeModel.UserName},
{ApiConstants.Password, apiAuthorizeModel.Password}
});

request.Headers.Add("X-PrettyPrint", "1");
var response = client.PostAsync(apiAuthorizeModel.TokenURI, request).Result;
jsonResponse = response.Content.ReadAsStringAsync().Result;
}
JObject jObject = JObject.Parse(jsonResponse);
Error = (string)jObject[ApiConstants.error];
ErrorDescription = (string)jObject[ApiConstants.error_description];
if (string.IsNullOrEmpty(Error))
{
AuthToken = (string)jObject[ApiConstants.AccessToken];
}
else
{
Log.Error(Error, typeof(SendDataToApi));
Log.Error(ErrorDescription, typeof(SendDataToApi));
isAPIErrorFlag = true;
}
}
return AuthToken;
}
catch (Exception e)
{
Log.Error("Method : GetAuthorizationKey :", e, typeof(SendDataToApi));
Log.Error(string.Concat("GetAuthorizationKey: ", e.Message.ToString()), typeof(SendDataToApi));
return null;
}
}

2656 18:37:22 INFO Method : GetAuthorizationKey :System.AggregateException: One or more errors occurred. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 101.53.162.131:443 at System.Net.Sockets.Socket.InternalEndConnect(IAsyncResult asyncResult) at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) --- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context) at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)

最佳答案

感谢您提出宝贵意见。我已使用此信息在您的 CRM 服务器和代理服务器之间建立连接。

根据您的环境,将服务器配置为允许流量通过位于 machine.config 或服务器根 web.config(IIS 级别)的代理。

<system.net> 
<defaultProxy>
<proxy usesystemdefault = "false" proxyaddress="http://ip address:port" bypassonlocal="false"/>
</defaultProxy>
</system.net>

它解决了我的问题。我引用的以下网站

https://help.salesforce.com/articleView?id=mc_mdc_crm_server_proxy_configuration.htm&type=5

关于c# - 无法将数据发布到 UAT 服务器中的 Salesforce,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57972935/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com