我们如何使用librets c#下载房产图片?
我试过这里的代码,但它不工作,显示图片大小为1KB 下面是我试过的代码我们如何使用librets c#下载房产图片?,c#,rets,C#,Rets,我试过这里的代码,但它不工作,显示图片大小为1KB 下面是我试过的代码 using (librets.GetObjectRequest request = new GetObjectRequest("Property", "Photo")) { request.AddAllObjects(CurrentMLS); GetObjectResp
using (librets.GetObjectRequest request = new GetObjectRequest("Property", "Photo"))
{
request.AddAllObjects(CurrentMLS);
GetObjectResponse response = session.GetObject(request);
foreach (ObjectDescriptor objectDescriptor in response)
{
string objectKey = objectDescriptor.GetObjectKey();
int objectId = objectDescriptor.GetObjectId();
string contentType = objectDescriptor.GetContentType();
string description = objectDescriptor.GetDescription();
Console.Write(objectKey + " object #" + objectId);
if (description.Length != 0)
Console.Write(", desription: " + description);
Console.WriteLine();
string outputFileName = photoFilePath+"\\"+objectKey + "-" + objectId + ".jpg";
Stream outputStream = File.OpenWrite(outputFileName);
const int BUFFER_SIZE = 1024;
Stream stream = objectDescriptor.GetDataStream();
byte[] buffer = new Byte[BUFFER_SIZE];
int bytesRead;
while ((bytesRead = stream.Read(buffer, 0, BUFFER_SIZE)) > 0)
{
outputStream.Write(buffer, 0, bytesRead);
}
outputStream.Close();
}
}
看起来你不是在按内容类型过滤。如果您信任RETS服务器发送正确格式的内容类型字符串,则可以仅使用以下内容将对象过滤为JPEG:
string contentType = objectDescriptor.GetContentType();
// skip objects that don't appear to be JPEGs
if (contentType != "image/jpeg") { continue; };
关闭原因消息链接令人困惑。我所说的“接近票”的意思是解释发生了什么以及你期望发生什么。在文本编辑器中打开生成的文件