是否可以对 CSV 进行 API 调用?

问题描述 投票:0回答:1

我正在尝试访问此 URL 中的数据:

http://files.intelligentreach.com/feedexports/bec25c7e-cbcd-460d-81d5-a25372d2e3d7/Currys_Zoovu_Template.csv

如何动态访问这些数据? 我可以进行 API 调用吗?如果是的话怎么办?

csv fetch-api export-to-csv csvhelper
1个回答
0
投票

这不是 API 调用,您只需要使用

HttpClient
来请求文件。让我有点困惑的是该文件已使用 GZip 压缩,因此您需要先解压缩该文件才能使用它。

async void Main()
{
    var requestUri = new Uri("http://files-as.intelligentreach.com/feedexports/bec25c7e-cbcd-460d-81d5-a25372d2e3d7/Currys_Zoovu_Template.csv");
    HttpClientHandler handler = new HttpClientHandler()
    {
        AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
    };
    using (var client = new HttpClient(handler))
    using (var request = new HttpRequestMessage(HttpMethod.Get, requestUri))
    using (var stream = await (await client.SendAsync(request)).Content.ReadAsStreamAsync())
    using (var reader = new StreamReader(stream))
    using (var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture)
    {
        Delimiter = "|"
    }))
    {
        var records = csv.GetRecords<Zoovu>().ToList();
    }
}

public class Zoovu
{
    [Name("name")]
    public string Name { get; set; }
    [Name("offer url")]
    public string OfferUrl { get; set; }
    [Name("image url")]
    public string ImageUrl { get; set; }
    [Name("Now price")]
    public string NowPrice { get; set; }
    [Name("sku")]
    public string Sku { get; set; }
    [Name("stock")]
    public string Stock { get; set; }
    [Name("Was price")]
    public string WasPrice { get; set; }
    [Name("brand")]
    public string Brand { get; set; }
    [Name("screen size")]
    public string ScreenSize { get; set; }
    [Name("description")]
    public string Description { get; set; }
    [Name("currency")]
    public string Currency { get; set; }
    [Name("colour")]
    public string Colour { get; set; }
    [Name("breadcrumb")]
    public string Breadcrumb { get; set; }
    [Name("Short Name")]
    public string ShortName { get; set; }
    [Name("Base Name")]
    public string BaseName { get; set; }
    [Name("MPN")]
    public string Mpn { get; set; }
    [Name("zoovu_height")]
    public string ZoovuHeight { get; set; }
    [Name("zoovo_device_type")]
    public string ZoovoDeviceType { get; set; }
    [Name("zoovo_laptop_type")]
    public string ZoovoLaptopType { get; set; }
    [Name("zoovo_2in1")]
    public string Zoovo2In1 { get; set; }
    [Name("zoovo_screen_size")]
    public string ZoovoScreenSize { get; set; }
    [Name("zoovu_touchscreen")]
    public string ZoovuTouchscreen { get; set; }
    [Name("zoovo_bluetooth")]
    public string ZoovoBluetooth { get; set; }
    [Name("zoovo_installed_ram")]
    public string ZoovoInstalledRam { get; set; }
    [Name("zoovo_harddrive_capacity")]
    public string ZoovoHarddriveCapacity { get; set; }
    [Name("zoovo_harddrive_capacity_unit")]
    public string ZoovoHarddriveCapacityUnit { get; set; }
    [Name("zoovo_operating_system")]
    public string ZoovoOperatingSystem { get; set; }
    [Name("zoovo_processor_brand")]
    public string ZoovoProcessorBrand { get; set; }
    [Name("zoovo_estimated_battery_life")]
    public string ZoovoEstimatedBatteryLife { get; set; }
    [Name("zoovo_processor_model")]
    public string ZoovoProcessorModel { get; set; }
    [Name("zoovo_fingerprint")]
    public string ZoovoFingerprint { get; set; }
    [Name("zoovo_weight")]
    public string ZoovoWeight { get; set; }
    [Name("zoovo_weight_unit")]
    public string ZoovoWeightUnit { get; set; }
    [Name("OEL_TRUE")]
    public string OelTrue { get; set; }
    [Name("SBRE_TRUE")]
    public string SbreTrue { get; set; }
}

© www.soinside.com 2019 - 2024. All rights reserved.