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

Error making http request #925

Closed
jonny-xhl opened this issue Jun 13, 2019 · 7 comments · Fixed by #1377
Closed

Error making http request #925

jonny-xhl opened this issue Jun 13, 2019 · 7 comments · Fixed by #1377
Assignees
Labels
bug Identified as a potential bug merged Issue has been merged to dev and is waiting for the next release

Comments

@jonny-xhl
Copy link

logs

warn: Ocelot.Responder.Middleware.ResponderMiddleware[0]
      requestId: 0HLNFQME9O0DV:00000001, previousRequestId: no previous request id, message: Error Code: UnableToCompleteRequestError Message: Error making http request, 
	exception: System.Net.Http.HttpRequestException: 请求的名称有效,但是找不到请求的类型的数据。 
	---> System.Net.Sockets.SocketException: 请求的名称有效,但是找不到请求的类型的数据。
         at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
         --- End of inner exception stack trace ---
         at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
         at System.Threading.Tasks.ValueTask`1.get_Result()
         at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
         at System.Threading.Tasks.ValueTask`1.get_Result()
         at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)
         at System.Threading.Tasks.ValueTask`1.get_Result()
         at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
         at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
         at Ocelot.Requester.HttpClientHttpRequester.GetResponse(DownstreamContext context) errors found in ResponderMiddleware. Setting error response for request path:/auth/token, 
	 request method: POST

consul server config

{
  "encrypt": "7TnJPB4lKtjEcCWWjN6jSA==",
  "services": [
    {
      "id": "Service1",
      "name": "Service1",
      "tags": [ "Service1" ],
      "address": "192.168.1.139",
      "port": 5011,
      "checks": [
        {
          "id": "Service1_Check",
          "name": "Service1_Check",
          "http": "http://192.168.1.139:5011/api/health",
          "interval": "10s",
          "tls_skip_verify": false,
          "method": "GET",
          "timeout": "1s"
        }
      ]
    },
    {
      "id": "Service2",
      "name": "Service2",
      "tags": [ "Service2" ],
      "address": "192.168.1.139",
      "port": 5021,
      "checks": [
        {
          "id": "Service2_Check",
          "name": "Service2_Check",
          "http": "http://192.168.1.139:5021/api/health",
          "interval": "10s",
          "tls_skip_verify": false,
          "method": "GET",
          "timeout": "1s"
        }
      ]
    },
    {
      "id": "IdentityServer",
      "name": "IdentityServer",
      "tags": [ "IdentityServer-tag" ],
      "address": "192.168.1.139",
      "port": 5001,
      "checks": [
        {
          "id": "IdentityServer_Check",
          "name": "IdentityServer_Check",
          "http": "http://192.168.1.139:5001/api/values",
          "interval": "10s",
          "tls_skip_verify": false,
          "method": "GET",
          "timeout": "1s"
        }
      ]
    },
    {
      "id": "APIGateway",
      "name": "APIGateway",
      "tags": [ "APIGateway" ],
      "address": "192.168.1.139",
      "port": 1001
    }
  ]
}

ocelot application server config

{
  "ReRoutes": [
    //identityserver4  token
    {

      "DownstreamPathTemplate": "/connect/token",
      "DownstreamScheme": "http",
      /*"DownstreamHostAndPorts": [
        {
          "Host": "192.168.1.139",
          "Port": "5001"
        }
      ],*/
      "ServiceName":"IdentityServer",
      "UpstreamPathTemplate": "/auth/token",
      "UpstreamHttpMethod": ["Post"],
      "UseServiceDiscovery": false,
      "DangerousAcceptAnyServerCertificateValidator": false
    },
    // API:Service1
    {
      "AuthenticationOptions": {
        "AuthenticationProviderKey": "service1Identity",
        "AllowedScopes": []
      },
      "DownstreamPathTemplate": "/api/{url}",
      "DownstreamScheme": "http",
      /*"DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": "5011"
        }
      ],*/
      "ServiceName":"Service1",
      "UpstreamPathTemplate": "/Service1/{url}",
      "UpstreamHttpMethod": [ "Get", "Post" ],
      "UseServiceDiscovery": false,
      "DangerousAcceptAnyServerCertificateValidator": false
    },
    // API:Service2
    {
      "AuthenticationOptions": {
        "AuthenticationProviderKey": "service2Idnetity",
        "AllowedScopes": []
      },
      "DownstreamPathTemplate": "/api/{url}",
      "DownstreamScheme": "http",
      /*"DownstreamHostAndPorts": [
        {
          "Host": "192.168.1.139",
          "Port": "5021"
        }
      ],*/
      "ServiceName":"Service2",
      "UpstreamPathTemplate": "/Service2/{url}",
      "UpstreamHttpMethod": [ "Get", "Post" ],
      "UseServiceDiscovery": false,
      "DangerousAcceptAnyServerCertificateValidator": false
    }
  ],
  "GlobalConfiguration": {
    "ServiceDiscoveryProvider": {
      "Host": "192.168.1.181",
      "Port": 8500,
      "Type": "Consul"
    },
    "RateLimitOptions": {

      "ClientIdHeader": "client_id",

      "QuotaExceededMessage": "Too Many Requests!!!",

      "DisableRateLimitHeaders": false

    }
  }
}

1、when I request http://192.168.1.139:1001/auth/token and then response 500 httpstatuscode.

@jonny-xhl
Copy link
Author

Config ReRoutes use DownstreamHostAndPorts can success,but use ServiceName throw exception.

@yuft
Copy link

yuft commented Jun 13, 2019

I guess this is more of a Consul health check definition problem, not Ocelot related.

HTTP checks also support TLS. By default, a valid TLS certificate is expected. Certificate verification can be turned off by setting the tls_skip_verify field to true in the check definition.

https://www.consul.io/docs/agent/checks.html

@jonny-xhl
Copy link
Author

I try setting tls_skip_verify field to true,but also throw the exception

@jonny-xhl
Copy link
Author

@yuft ,Can you tell me Consul health check definetion where is problem.
The consul web ui show check success.

@yuft
Copy link

yuft commented Jun 14, 2019

Just saw you had "UseServiceDiscovery": false, maybe you can remove it and see if it makes any difference.

@jonny-xhl
Copy link
Author

jonny-xhl commented Jun 14, 2019

Just saw you had "UseServiceDiscovery": false, maybe you can remove it and see if it makes any difference.

Now,I setting sigle Consul server can success.
Don't change Ocelot config.
consul web ui

Post

@raman-m raman-m self-assigned this Sep 25, 2023
@raman-m raman-m added the bug Identified as a potential bug label Sep 25, 2023
@raman-m
Copy link
Member

raman-m commented Sep 25, 2023

@jonny-xhl
I believe PRs #1670, #1377 should resolve your problem. If Not then it seems it's Consul configuration issue.
Let me know testing results please!

raman-m added a commit that referenced this issue Sep 28, 2023
…tificateValidator (#1377)

* Fix/1375 fix DownstreamRoute DangerousAcceptAnyServerCertificateValidator does not work

* Fix the exception when RoundRobin services is empty

* Fix build errors

* IDE0063 'using' statement can be simplified

* IDE0051 Private member 'StreamCopyBufferSize' is unused

* Use nameof() in string interpolations

* @RaynaldM code review

* Code review. Refactor method

* Organize folders for WebSockets feature

* Add unit tests class for WebSockets feature

* Refactor middleware to make it suitable for unit testing

* Add unit test

* Review current acceptance tests for WebSockets

* Review

---------

Co-authored-by: raman-m <[email protected]>
@raman-m raman-m added the merged Issue has been merged to dev and is waiting for the next release label Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Identified as a potential bug merged Issue has been merged to dev and is waiting for the next release
Projects
None yet
3 participants