Rurilib.HTTP

           var settings = new ProxySettings();
            var proxyClient = new NoProxyClient(settings);

            // Create the custom proxied client
            using var client = new RLHttpClient(proxyClient);

            // Create the request
            using var request = new HttpRequest
            {
                Uri = new Uri("uri"),
                Method = HttpMethod.Post,
                Headers = new Dictionary<string, string>
                {
                    { "User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)" },
                    { "Pragma", "no-cache" },
                    { "Accept","*/*" }
                },
                Cookies = new Dictionary<string, string>
                {

                },

                // Content a.k.a. the "post data"
                Content = new StringContent("postData", Encoding.UTF8, "application/json")
            };

            // Send the request and get the response (this can fail so make sure to wrap it in a try/catch block)
            try 
            {
                using var response = await client.SendAsync(request);

                // Read and print the content of the response
                var content = await response.Content.ReadAsStringAsync();
                if (content.Contains("Token"))
                {
                    

                }

            } catch(Exception ex)
            {
                if (ex.Message.Contains("invalid")) { Console.WriteLine("BAD");}
                else if(ex.Message.Contains("_INVALID") || ex.Message.Contains("_EXCEEDED")) { 
                Console.WriteLine("RETRY"); }
                else { Console.WriteLine(ex.Message); }
                
            }

here I made a request now if the source contains a token I want to make another request. So I want to ask do I need to create the whole request again from

 using var request = new HttpRequest

or can I use the above-declared request?

1 Like

You can use the same request, just change its fields (Uri, Method etc.) accordingly.

1 Like
 try
            {
               
                using var response = await client.SendAsync(request);
               
                // Read and print the content of the response

                var content = await response.Content.ReadAsStringAsync();

                
               
            }
            catch(Exception ex)
            {
               
            }

I want to ask If I get a response with a 400 status code and If I want to add an if condition, where should I place the code in a try block or in a catch block?

1 Like

Unlike xNet, you will not get an exception on a 4xx or 5xx response. You only get exceptions for connection issues and such. So just make a check on response.StatusCode (or something similar, I don’t remember the exact name right now) right before you read the content and you’re good to go.

2 Likes

Ahhh that’s fascinating

1 Like

@Ruri is ObservableCollection is good for storing proxies?

1 Like

Usually an ObservableCollection<T> is used to notify somebody when the collection is changed (often the UI, to redraw something on screen). If that’s what you need it to do then yes sure, I think it’s backed by a normal List<T> internally. Otherwise just use a normal List<T> without the overhead code.

2 Likes

Since you talk about UI I’m facing one issue with my tool although I’m also using INotifyPropertyChanged everything is working but once I navigate from one page to other everything seems stuck like progress and good and bad count. But when I navigate again from another page to the current it refreshes the UI and again stuck
My INotifyPropertyChanged code.

 public class ViewModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
 public class Stats : ViewModelBase
    {
private static int bad = 0;
public int Bad { get => bad; set { bad = value; OnPropertyChanged(nameof(Bad)); } }
}
1 Like

Sorry I don’t have the time to help with this, but I use the same thing on OB2 and it’s working fine. Maybe you’re not attaching to the previous view model correctly when you put back the page on the window? See how it’s done in OB2 Native and use that as a reference.

1 Like

Thanks, I can understand, just wanted to ask one thing
is this the right way to navigate from one page to other

mainFrame.Content = new Settings();
mainFrame.Content = new Home();
mainFrame.Content = new Result();

Well no, you’re recreating a new page each time so you lose the previous one you had (alongside its viewmodel). Why don’t you cache the pages as a singleton? Otherwise you could just cache the viewmodels (like I do) and reattach them to the page as soon as it’s created. Seriously, look at how I implemented it in OB2 Native client.

1 Like

Ok thanks I’ll take a look at it

@Ruri, what is the best way if I need to create multiple requests

 var settings = new ProxySettings();
            var proxyClient = new NoProxyClient(settings);

            // Create the custom proxied client
            using var client = new RLHttpClient(proxyClient);

            // Create the request
            using var request = new HttpRequest
            {
                Uri = new Uri("https://httpbin.org/anything"),
                Method = HttpMethod.Post,
                Headers = new Dictionary<string, string>
                {
                    { "Authorization", "Bearer ey..." }
                },
                Cookies = new Dictionary<string, string>
                {
                    { "PHPSESSID", "12345" }
                },

                // Content a.k.a. the "post data"
                Content = new StringContent("My content", Encoding.UTF8, "text/plain")
            };

            // Send the request and get the response (this can fail so make sure to wrap it in a try/catch block)
            using var response = await client.SendAsync(request);

            // Read and print the content of the response
            var content = await response.Content.ReadAsStringAsync();
            if(content.contains()){

}
            Console.WriteLine(content);

Suppose there are two or more requests after the if condition. Should I create another request again, like the above-mentioned request, or can I use the above one to perform multiple requests?

If I want to use SystemNET instead of RurilibHTTP, like this
Capture

then what to change here

var settings = new ProxySettings();
            var proxyClient = new NoProxyClient(settings);

            // Create the custom proxied client
            using var client = new RLHttpClient(proxyClient);

            // Create the request
            using var request = new HttpRequest
            {
                Uri = new Uri("https://httpbin.org/anything"),
                Method = HttpMethod.Post,
                Headers = new Dictionary<string, string>
                {
                    { "Authorization", "Bearer ey..." }
                },
                Cookies = new Dictionary<string, string>
                {
                    { "PHPSESSID", "12345" }
                },

                // Content a.k.a. the "post data"
                Content = new StringContent("My content", Encoding.UTF8, "text/plain")
            };

            // Send the request and get the response (this can fail so make sure to wrap it in a try/catch block)
            using var response = await client.SendAsync(request);

            // Read and print the content of the response
            var content = await response.Content.ReadAsStringAsync();
            if(content.contains()){

}
            Console.WriteLine(content);