question

Upvotes
Accepted
36 6 1 14

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 5.0 MiB each and 10.0 MiB total.

Upvotes
Accepted
38.1k 71 35 53
@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 5.0 MiB each and 10.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 5.0 MiB each and 10.0 MiB total.

Upvotes
36 6 1 14

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 5.0 MiB each and 10.0 MiB total.

Upvotes
36 6 1 14

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 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea