C# 无法将数据发布到UAT服务器中的Salesforce
我已经创建了一个api请求来发布表单数据,以在salesforce中创建lead 首先,我请求了向salesforce插入数据的授权密钥 (使用oauth、客户端id和客户端机密。) 这在本地起作用,数据在salesforce中成功发布。 接下来,我将此代码移动到UAT服务器。在该UAT服务器中,我无法获取授权密钥,并且数据未发布到salesforce 下面是我在日志文件中发现的错误C# 无法将数据发布到UAT服务器中的Salesforce,c#,api,salesforce,C#,Api,Salesforce,我已经创建了一个api请求来发布表单数据,以在salesforce中创建lead 首先,我请求了向salesforce插入数据的授权密钥 (使用oauth、客户端id和客户端机密。) 这在本地起作用,数据在salesforce中成功发布。 接下来,我将此代码移动到UAT服务器。在该UAT服务器中,我无法获取授权密钥,并且数据未发布到salesforce 下面是我在日志文件中发现的错误 //Function to Get Authorization public static s
//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;
}
}
//获取授权的函数
公共静态字符串GetAuthorizationKey(ApiAuthorizationModel ApiAuthorizationModel)
{
尝试
{
string jsonResponse=string.Empty;
string AuthToken=string.Empty;
字符串错误=string.Empty;
string ErrorDescription=string.Empty;
如果(!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;
使用(var client=new HttpClient())
{
var请求=新FormUrlEncodedContent(新字典{
{ApiConstants.Grant_type,ApiConstants.Password},
{ApiConstants.Client_key,apiAuthorizeModel.ClientID},
{ApiConstants.Client_secret,apiAuthorizeModel.ClientSecret},
{ApiConstants.Username,ApiConstants.Username},
{ApiConstants.Password,ApiConstants.Password}
});
请求。标题。添加(“X-PrettyPrint”,“1”);
var response=client.PostAsync(apiAuthorizeModel.TokenURI,request).Result;
jsonResponse=response.Content.ReadAsStringAsync().Result;
}
JObject=JObject.Parse(jsonResponse);
Error=(字符串)jObject[ApiConstants.Error];
ErrorDescription=(字符串)jObject[ApiConstants.error_description];
if(string.IsNullOrEmpty(Error))
{
AuthToken=(字符串)jObject[ApiConstants.AccessToken];
}
其他的
{
Log.Error(Error,typeof(SendDataToApi));
Log.Error(ErrorDescription,typeof(SendDataToApi));
IsapierorFlag=真;
}
}
返回AuthToken;
}
捕获(例外e)
{
Log.Error(“方法:GetAuthorizationKey:”,e,typeof(SendDataToApi));
Log.Error(string.Concat(“GetAuthorizationKey:”,e.Message.ToString()),typeof(SendDataToApi));
返回null;
}
}
2656 18:37:22信息方法:GetAuthorizationKey
:System.AggregateException:发生一个或多个错误。-->
System.Net.Http.HttpRequestException:发送时出错
请求。-->System.Net.WebException:无法连接到
远程服务器-->System.Net.Sockets.SocketException:连接
尝试失败,因为关联方没有正确响应
一段时间后,或建立的连接失败,因为
连接的主机未能在响应101.53.162.131:443
System.Net.Sockets.Socket.InternalEndConnect(IAsyncResult asyncResult)
在System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)上位于System.Net.ServicePoint.ConnectSocketInternal(布尔值 连接故障,插座s4,插座s6,插座和插座,IP地址& 地址,ConnectSocketState状态,IAsyncResult asyncResult, 异常和异常)---内部异常堆栈跟踪的结束---
在System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult)中 asyncResult、TransportContext和context)位于 System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
谢谢你的宝贵意见。我已使用此信息在CRM服务器和代理服务器之间建立连接 根据您的环境,将服务器配置为允许在machine.config或服务器的根web.config(IIS级别)通过代理进行通信
它解决了我的问题。
下面是我提到的网站
IP地址可能被阻止。因此,首先尝试使用cmd.exe>ping101.53.162.131进行PING。如果ping有效,则端口号被阻止或您无法进行身份验证。端口443是SSL/TTL,它需要一个证书,用户无法获得证书。我需要去那里解除阻止。你能帮个忙吗。请与我分享取消阻止/证书生成过程的步骤?首先验证它是端口块、坏证书(或错误位置)或坏IP。像wireshark或fiddler这样的嗅探器会有所帮助。您应该使用安全连接https,它在发出http请求之前首先使用TCP获得SSL/TLS安全连接。您的UAT服务器托管在哪里?你能做到吗?如果您正在管理它,那么将很容易取消阻止通信,或者如果有网络团队参与,他们将能够修改防火墙规则。这肯定是一个连接问题。我不能在UAT客户端中添加防火墙。这是我们的客户服务器。我需要帮助客户网络团队完成这项工作。但我不知道该怎么做。你能分享一下做这件事的步骤吗。
<system.net>
<defaultProxy>
<proxy usesystemdefault = "false" proxyaddress="http://ip address:port" bypassonlocal="false"/>
</defaultProxy>
</system.net>