How to get original response in case of exception

Hello, I hope you are doing great I wanted to know how can we get the original response from an HttpRequest.

try
{
 Using httprequest As HttpRequest = New HttpRequest
 Dim request1 = httprequest.get("google.com").tostring()
}
 Catch exception As HttpException
     textbox1.text = exception.Message
End Try


The thing I want is the original response in textbox1. Like if the response code is 401 then it shows an exception message not the original message from the server.

Sorry I don’t know VB

Here is the C# code

try
            {
                using(HttpRequest request = new HttpRequest())
                {
                    var response = request.Get("google.com").ToString();
                    Console.WriteLine(response);
                }
            }
            catch(HttpException ex)
            {
                Console.WriteLine(ex.Message);
            }

suppose the response code was 403 in that case execution will jump to catch block. But it won’t show the actual response from the server.

I assume you’re using xNet.
Just put this before the response

request.IgnoreProtocolErrors = true;

After adding this statement before response, I’m getting nothing on the console.

Sorry I’m not very knowledgeable with xNet anymore, it’s used by OB1 but I switched away from it in OB2 so it’s been long since I last used it. Maybe ask the original developers directly or wait until someone more knowledgeable helps you here ^^’

Any particular reason why you’re not using the default HttpClient in System.Net?

I feel xNet or Extreme.net has a more straightforward interface and is easy to use. However, I haven’t tried HttpClient or System.net before, but I’ll try to take a look at it.
Any Idea when we see an HTTP library like Parallelization from you.
And here is one thing more that I want to ask maybe this piece of code looks familiar to you.

 catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine(ex.Message);
                if (ex.GetType() == typeof(HttpException))
                {
                    responseCode = ((HttpException)ex).HttpStatusCode.ToString();
                    Console.WriteLine($"Response Code: {responseCode}");
                }
                throw;
            }

            return (address, responseCode, headers, cookies);

This is the piece of code from OB1 the only thing that I want to ask like if I use the invalid credentials in an HTTP request, OB shows response code as well as the message from the client side like

Unauthorized or Invalid email or password
But when I use the same piece of code it shows the response code but not the actual response from the server. Instead, I get errors on the client-side with 401.

Well, the one I’m talking about is the one made by Microsoft. You can find plenty of tutorials about it.

The library is already available as a nuget package, check the announcements section, there is also a discussion on this forum that goes pretty in depth

About the last thing, this is the code, I cannot help you more than this, as you can see there is the IgnoreProtocolErrors set to true as I was telling you, then I catch the exception and log ex.Message

1 Like

Ok thanks, I’ll check

I find Ruri HTTP and proxies in the announcement, but I’m unable to find an in-depth discussion on these two packages. Can you guide me to the correct section to search these discussions?

There is an in-depth discussion about RuriLib.Parallelization, not about the other two. But there are examples on github, and I can always help on the forum.

1 Like

ohhhh I got it. Thanks