架构师_程序员_码农网

Retrieve password
Register

QQ登录

Just one step to get started

Search
Views:23402|Responses: 0
打印 上一主题 下一主题

[ASP.NET]Ocelot Request headers must contain only ASCII characters

[Copy link]
跳转到指定楼层
owner of the building
发表于 2021-5-10 15:24:29| 看该作者回帖奖励|ReverseBrowse|Read Mode
Recap:

Ocelot Series (I) ASP.NET Core Gateway in Action
h ttps:// www.itsvse.com/thread-9284-1-1.html


Starting the ocelot gateway and accessing the interface reports the following error:
Status Code: 502; Bad Gateway & nbsp; &nbsp nbsp;         &nbsp nbsp;   &nbsp nbsp;         &nbsp nbsp;             &nbsp nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp nbsp;             &nbsp nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp nbsp;             &nbsp nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp nbsp;             &nbsp nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp nbsp;             &nbsp nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; nbsp
The project is ASP.NET Core 3.1 and Ocelot is using version 16.0.1.



info: Ocelot.RateLimit.Middleware.ClientRateLimitMiddleware[0]
requestId: 0HM8JAOKL2C09:00000006, previousRequestId: no previous request id, message: EndpointRateLimiting is not enabled for /{url}
warn: Ocelot.Responder.Middleware.
requestId: 0HM8JAOKL2C09:00000006, previousRequestId: no previous request id, message: Error Code. ConnectionToDownstreamServiceError Message: Error connecting to downstream service, exception: System.Net.Http. Request headers must contain only ASCII characters.
HttpRequestException: Request headers must contain only ASCII characters. at System.Net.Http.HttpConnection.WriteStringAsync(String s)
HttpConnection.WriteStringAsync(String s) at System.Net.Http.HttpConnection.WriteHeadersAsync(HttpHeaders headers, String CookiesFromContainer)
at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken HttpConnection.SendAsyncore(HttpRequestMessage request, CancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, CancellationToken) HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken HttpRequestMessage request, CancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts) CancellationTokenSource cts, Boolean disposeCts)
at Ocelot.Requester.HttpClientHttpRequester.GetResponse(HttpContext httpContext) errors found in ResponderMiddleware. Setting error response for request path:/test1/home/index, request method: GET
Use Fiddler to capture the following packet, and found that the cookie has Chinese strings, as follows:




Host: localhost:5002
Connection: keep-alive
Cache-Control: max-age=0
sec-ch-ua: "Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"
sec-ch-ua-mobile: ?0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed- exchange;v=b3;q=0.9
Sec-Fetch-Site: none
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cookie: aaa=test


The problem is reproduced by the browser writing the cookie code ( value is not escaped in the code below ):

Browser console writes cookie
h ttps:// www.itsvse.com/thread-4682-1-1.html
Try to clear the cookie cache, the gateway is back to normal as shown below:



Attachment Ocelot executes the middleware in the following order:

PreErrorResponderMiddleware
PreAuthenticationMiddleware
AuthenticationMiddleware
PreAuthorizationMiddleware
AuthorizationMiddleware
PreQueryStringBuilderMiddleware


(End)




Previous: ASP.NET Core get request full URL link
Next article: Redis Benchmark benchmark performance test
The code farmer network, only published in the practice process, encountered technical difficulties, do not mislead others.
You need to log in before you can post back Log in | Register

This version of the integral rules

DISCLAIMER:
All software, programming materials or articles published by Code Farmer are only used for learning and research purposes; the above contents shall not be used for commercial or illegal purposes, otherwise, all the consequences shall be borne by the users. This site information from the network, copyright dispute has nothing to do with this site. You must completely remove the above content from your computer within 24 hours of downloading. If you like the program, please support the genuine software, buy registration and get better genuine service. If there is any infringement, please contact us by email to deal with it.

Mail To:help@itsvse.com

QQ| ( ICP备14021824号-2 )|Sitemap

GMT+8, 2024-9-19 01:20

Quick ReplyBack to topBack to list