question

Upvotes
Accepted
36 10 5 15

Is there anyway to fetch the names of all complete files via Https method in C#?

Greetings all

Does anyone know how to fetch the file name list of api results as below, by using HttpWebRequest via C#? Thank you in advance!

tick-history-rest-api
无标题.png (130.3 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
Accepted
79.2k 251 52 74
@Leon.Hong

You can use FtpWebRequset to get the list of files in api-results directory. The snippet code is:

using System;
using System.Net;
using System.IO;


namespace FTPWebRequest
{
    class Program
    {
        static void Main(string[] args)
        {
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://tickhistory-ftp.thomsonreuters.com/api-results");
            request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

            // This example assumes the FTP site uses anonymous logon.
            request.Credentials = new NetworkCredential("Username", "Password");
            FtpWebResponse response = (FtpWebResponse)request.GetResponse();

            Stream responseStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(responseStream);
            Console.WriteLine(reader.ReadToEnd());
            Console.WriteLine("Directory List Complete, status {0}", response.StatusDescription);

            reader.Close();
            response.Close();
        }
    }
}

I go this code from https://msdn.microsoft.com/en-us/library/ms229716(v=vs.110).aspx.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
13.7k 26 8 12

@Leon.Hong

I do not know if you can do this using the current TRTH SOAP API.

But it will be possible with the TRTH REST API, for requests made using the REST API. The TRTH REST API is currently in EAP.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

C# code: run the TRTH REST API Quick Start, in left menu go to Scheduled Extractions - ExtractedFiles: Get Latest. Click C# Full to see it.

Extract:

var ExtractionsContext = new ExtractionsContext(new Uri("https://hosted.datascopeapi.reuters.com/RestApi/v1/"), "<userid>", "<pwd>");
ExtractionsContext.Preferences.MaxPageSize = 8;
//Return 1st page of latest Extracted Files:
var page = ExtractionsContext.ExtractedFileOperations.GetAll();
foreach (var file in page)Debug.WriteLine("Filename: {0}, Size: {2}, ContentsExist: {3}", file.ExtractedFileName, file.Size, file.ContentsExists);
Upvotes
36 10 5 15

Thank you Christiaan, I will check HOW REST API works.

But sadly, client is using the SOAP API, so I have to find out a way to resolve this..

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
36 10 5 15

This is how I sort it out

// 设置参数
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            //发送请求并获取相应回应数据
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;


            //直到request.GetResponse()程序才开始向目标网页发送Post请求
            Stream responseStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(responseStream);
            //Output
            string data = reader.ReadToEnd();


            MatchCollection matches = Regex.Matches(data, "<a(?:\\s+.+?)*?\\s+href=\"([^\"]*?)\".+>(.*?)</a>", RegexOptions.IgnoreCase);
            List<string> mList = new List<string>();
            foreach (Match match in matches)
            {
                string s = match.Groups[1].Value;
                Console.WriteLine(s);
                mList.Add(s);
            }
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.