I want to get an event through httpclient stream processing.

Asked 2 years ago, Updated 2 years ago, 351 views

Regarding the presentation code, below is the code for obtaining SNS timeline posts in the stream.The console screen is the output when a post arrives.

I want to know how to get the console output event:update.
I'm loading one line at a time, so I think you can get the first line and compare the strings.
It says evnet:, so I would like to know if there is a way to get it exclusively.

I checked the reference site, but I don't know how to get the stream because I don't see any functions to get it in GetStreamAsync and the return value in stream.

GetStreamAsync: https://learn.microsoft.com/ja-jp/dotnet/api/system.net.http.httpclient.getstreamasync?view=net-7.0#system-net-http-httpclient-getstreamasync(system-uri-system-threading-cancellationtoken)

stream:https://learn.microsoft.com/ja-jp/dotnet/api/system.io.stream?view=net-7.0

Ahhhhhhhhhhhhhh!
:)
—thump
event:update
data: { "id": "109363075575162689", "created_at": "2022-11-18T05:08:21.428Z", "in_reply_to_id": null, "in_reply_to_account_id":
...
...
omission

//var response=wait client.GetAsync("https://"+instance+"/api/v1/timelines/home?"+Method_Parameter.GetHomeTimeLine(auth_code, since_id, max_id, min_id, limit, local).Reeds;Routing)
                var response=wait client.GetStreamAsync("https://mstdn.jp/api/v1/streaming/user");
                // var response = wait client.GetStreamAsync("https://mstdn.jp/api/v1/streaming/public");
            var streamReader = new StreamReader (response);

            US>string?str=null;
            
            while(true)
            {
                var message = wait streamReader.ReadLineAsync();
                if(message==null)
                {
                    break;
                }
                else
                {
                    str+=message;
                }

                Console.WriteLine(message);
            }


                Console.WriteLine(str);
                JOBject json = JOBject.Parse(str);
                foreach (vare in json)
                {
                    Console.WriteLine(e);
                }
               

c#

2022-11-19 04:08

1 Answers

I want to know how to get the console output event:update.
I'm loading one line at a time, so I think you can get the first line and compare the strings.

Have you lost track of the purpose of the program and what to do after you get it? It is said that it is outside the scope of the question, but will the data be analyzed after the acquisition?
If so, you should reverse the order, parse the entire stream, and find the part that corresponds to event:update in the analysis results.(Otherwise, someone's tote might simply contain the string event:update and cause the stream analysis to fail.)

It says evnet:, so I would like to know if there is a way to get it exclusively.

It's just a string.There is no special meaning and no dedicated action.


2022-11-19 16:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.