Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I configure Proxy? #54

Closed
RenanDelacroix opened this issue Oct 9, 2019 · 7 comments
Closed

How do I configure Proxy? #54

RenanDelacroix opened this issue Oct 9, 2019 · 7 comments

Comments

@RenanDelacroix
Copy link

Hi, I need to configure a proxy on the request. But I can't find any information of how do I do that.
Can you Help me?
How can I set my Proxy configuration in FluentlyHttpClient.

@stephenlautier
Copy link
Member

How would configure the proxy in the traditional HttpClient? Are you referring to the MessageHandler?

@RenanDelacroix
Copy link
Author

I'm referring to the proxy credentials.
If I would configure at traditional client it would be like at the end of the message.
I wanted to know how can I set credentials and set that by using Fluently.

//Example of traditional Client:
var proxy = new WebProxy
{
Address = new Uri($"http://{proxyHost}:{proxyPort}"),
BypassOnLocal = false,
UseDefaultCredentials = false,

// *** These creds are given to the proxy server, not the web server ***
Credentials = new NetworkCredential(
    userName: proxyUserName,
    password: proxyPassword)

};

// Now create a client handler which uses that proxy
var httpClientHandler = new HttpClientHandler
{
Proxy = proxy,
};

// Omit this part if you don't need to authenticate with the web server:
if (needServerAuthentication)
{
httpClientHandler.PreAuthenticate = true;
httpClientHandler.UseDefaultCredentials = false;

// *** These creds are given to the web server, not the proxy server ***
httpClientHandler.Credentials = new NetworkCredential(
    userName: serverUserName,
    password: serverPassword);

}

// Finally, create the HTTP client object
var client = new HttpClient(handler: httpClientHandler, disposeHandler: true);

@stephenlautier
Copy link
Member

stephenlautier commented Oct 9, 2019

Ah yea for the MessageHandler as i suspected

Quite simple

fluentHttpClientBuilder.WithMessageHandler(httpClientHandler)

for a complete example you can see tests such as this https://github.com/sketch7/FluentlyHttpClient/blob/master/test/LoggingHttpMiddlewareTest.cs#L29

@RenanDelacroix
Copy link
Author

Hi!
I thank you...
But, i just did as you said and it doesn't work, I can't reach the endpoint.
I tested in orginal httpClient and worked fine. When I try to use Fluently it just respond some erros...
When I try to see the Result I got Exception.

Follows the message:

image

@RenanDelacroix
Copy link
Author

And that's the exception:

"detail": "One or more errors occurred. (Response status code does not indicate success: 404 ().)",
"innerException": "Response status code does not indicate success: 404 ().",
"innerExceptionInnerExpetion": "",
"targetSite": "GetResultCore"

@RenanDelacroix
Copy link
Author

@stephenlautier
Copy link
Member

Opps sorry.. by mistake i linked from a branch - updated https://github.com/sketch7/FluentlyHttpClient/blob/master/test/LoggingHttpMiddlewareTest.cs#L29

Strange, it should work - theres not much adding to it from my end when setting the HttpMessageHandler

If you can either provide me a working example which I can check or at least send me how you're configuring fluently with the message handler maybe I can help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants