我有C#批处理,它通过SOAP API与salesforce对象进行通信。 我想获取一个图像,该图像是salesforce自定义对象中Rich Text字段的一部分。 富文本字段本身是Html文本,我可以获取图像标记的url,但问题是url本身是Https = Http安全连接:
https://ngam--kerensen--c.cs17.content.force.com/servlet/rtaImage?eid=a1Vg0000000lTkK&feoid=00N20000003jcie&refid=0EMg00000009N4
我
因此,我无法获取资源并将其作为本地映像写入文件以供以后使用。 这是用于获取图像的C#代码:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
bool answer = response.ContentType.StartsWith("image", StringComparison.OrdinalIgnoreCase);
if ((response.StatusCode == HttpStatusCode.OK ||
response.StatusCode == HttpStatusCode.Moved ||
response.StatusCode == HttpStatusCode.Redirect)&&
response.ContentType.StartsWith("text/html", StringComparison.OrdinalIgnoreCase)){
// if the remote file was found, download it
using (Stream inputStream = response.GetResponseStream())
using (Stream outputStream = File.OpenWrite(filepath))
{
byte[] buffer = new byte[8192];
int bytesRead;
logger.InfoFormat("Writing to file, filepath:{0}", filepath);
do
{
bytesRead = inputStream.Read(buffer, 0, buffer.Length);
logger.InfoFormat("bytesRead: {0} ", bytesRead);
outputStream.Write(buffer, 0, bytesRead);
} while (bytesRead != 0);
//TODO outputStream.Close();
}
return true;
}
}
catch (Exception ex)
{
logger.ErrorFormat("Failed to download {0} to {1} : {2}",
uri, filepath, ex.Message);
logger.Debug("Failed to download " + uri, ex);
}
return false;
我知道安全url使用java servlet将图像暴露给世界。 问题是我无法获取图像数据并始终得到以下响应:
<script>
if (this.SfdcApp && this.SfdcApp.projectOneNavigator) { SfdcApp.projectOneNavigator.handleRedirect('https://ngam--kerensen.cs17.my.salesforce.com?ec=302&startURL=%2Fcontent%2Fsession%3Furl%3Dhttps%253A%252F%252Fngam--kerensen--c.cs17.content.force.com%252Fservlet%252FrtaImage%253Feid%253Da1Vg0000000lTkK%2526feoid%253D00N20000003jcie%2526refid%253D0EMg00000009N4I'); } else
if (window.location.replace){
window.location.replace('https://ngam--kerensen.cs17.my.salesforce.com?ec=302&startURL=%2Fcontent%2Fsession%3Furl%3Dhttps%253A%252F%252Fngam--kerensen--c.cs17.content.force.com%252Fservlet%252FrtaImage%253Feid%253Da1Vg0000000lTkK%2526feoid%253D00N20000003jcie%2526refid%253D0EMg00000009N4I');
} else {;
window.location.href ='https://ngam--kerensen.cs17.my.salesforce.com?ec=302&startURL=%2Fcontent%2Fsession%3Furl%3Dhttps%253A%252F%252Fngam--kerensen--c.cs17.content.force.com%252Fservlet%252FrtaImage%253Feid%253Da1Vg0000000lTkK%2526feoid%253D00N20000003jcie%2526refid%253D0EMg00000009N4I';
}
</script>
有关如何从Rich Text Area字段获取实际图像数据的任何建议。