如何将文件提供给telnet(how to feed a file to telnet)
试图理解我用telnet发送请求的http和标题。 不要一次又一次地输入所有的东西,我想我会用我需要的所有命令写一个小文本文件。
我的文件很简单,如下所示:
GET /somefile.php HTTP/1.1 Host: localhost
然后我尝试用io-redirection将它提供给telnet:
$ telnet localhost 80 < telnet.txt
但我得到的所有输出是
Trying ::1... Connected to localhost. Escape character is '^]'. Connection closed by foreign host.
我究竟做错了什么?
trying to understand http and headers i was playing around with telnet to send requests. to not type everything again and again and again i thought i'd write a small textfile with all the commands i need.
my file is as simple as follows:
GET /somefile.php HTTP/1.1 Host: localhost
i then try to feed it to telnet with io-redirection:
$ telnet localhost 80 < telnet.txt
but all output i get is
Trying ::1... Connected to localhost. Escape character is '^]'. Connection closed by foreign host.
what am i doing wrong?
原文:https://stackoverflow.com/questions/2639419
最满意答案
有什么理由让它保持异步吗?
那真的取决于你。 如果您确实需要利用能够扩展的异步操作,那么请保留它。 否则,如果不这样做,请使用同步API。 这完全取决于您以及您在代码库中实际使用的内容。
我理解你担心异步方法“一路走来”并且实际上改变你的整个代码库变成异步这一事实。 这就是为什么你应该这样做,只要它是值得的。
附注 - 您可以稍微修改您的代码以节省自己的异步状态机生成:
private Task<List<stuff>> GetData() { return _appCache.GetAsync("SiteStructurePages", () => _repository.GetSomeStuff()); }
is there any reason to keep it async?
That really depends on you. If you actually need to take advantage of asynchronous operations, which is being able to scale, then do keep it. Otherwise, if you don't, use a synchronous API. it's all up to you and what you actually make use of in your code base.
I understand the fact that you're worried about async methods going "all the way" and actually altering your entire code-base to become async. That's why you should do it as long as it's worth it.
Side note - you can slightly modify your code to save yourself the async state-machine generation:
private Task<List<stuff>> GetData() { return _appCache.GetAsync("SiteStructurePages", () => _repository.GetSomeStuff()); }
相关问答
更多-
在这里得到了答案: https : //github.com/spring-projects/spring-security-oauth/issues/736 显然,解决方法是配置security.filter-dispatcher-types=REQUEST, ERROR got an answer here: https://github.com/spring-projects/spring-security-oauth/issues/736 apparently the fix is to confi ...
-
在C#中使代码异步(Make the code asynchronous in C#)[2022-07-05]
您可以使用Task.WhenAll来等待一系列任务: public static async TaskSendToAllIps(string req) { var tasks = _allIps.Select(ip => SendRequest(new Uri(ip + req))); return await Task.WhenAll(tasks); } You can use Task.WhenAll to await a collection of tasks: ... -
C#缓存和异步请求(C# caching and async requests)[2023-10-29]
有什么理由让它保持异步吗? 那真的取决于你。 如果您确实需要利用能够扩展的异步操作,那么请保留它。 否则,如果不这样做,请使用同步API。 这完全取决于您以及您在代码库中实际使用的内容。 我理解你担心异步方法“一路走来”并且实际上改变你的整个代码库变成异步这一事实。 这就是为什么你应该这样做,只要它是值得的。 附注 - 您可以稍微修改您的代码以节省自己的异步状态机生成: private Task- > GetData()
{
return _appCache.GetAsync(" ...
-
异步/等待和缓存(Async/Await and Caching)[2024-03-29]
它看起来像缓存管理器执行所有的“检查它存在,如果不运行lambda然后存储”。 如果是这样的话,唯一的方法是创建一个GetAsync方法,该方法返回一个Task而不是Store ,即 public virtual Task GetStoreByUsernameAsync(string username) { return _cacheManager.GetAsync(string.Format("Cache_Key_{0}", username), () => { ... -
c#阻止异步方法中的代码(c# blocking code in async method)[2023-01-05]
如果你有完全同步的代码,你不能改变它以使它返回一个等待状态,并且想使它异步,那么是的,如果你想使用async/await ,你唯一的选择就是使用Task.Run() 。 就像是: public async TaskMyMethod() { T result = await Task.Run(() => CheckCacheOnSyncMethodICantChange()); if(result != null) { result = await MyLibraryMet ... -
使用WebRequest.BeginGetResponse而不是GetResponse,并在回调方法中将序列化结果分配给List 不要忘记,将另一个线程的数据分配给另一个线程中创建的UI元素时,应该使用调度程序向UI发送消息 希望这可以帮助 Use WebRequest.BeginGetResponse Instead of GetResponse, and assign the serialized result to List in callback method Don't forgot that f ...
-
将getItemView()方法更改为Task返回,如下所示: private async Task getItemView() 然后代替使用Task.Run只需在click事件处理程序中await此调用,如下所示: await getItemView(); Thanks for the advice on my TAP patterns, definitely learning a lot about TAP. The solution to my problem was the HttpWebReq ...
-
Varnish通过宽限模式绝对支持这一点。 您将需要一些VCL代码魔法来启用宽限模式 。 这是它的内容: 初始请求会很慢。 它将被缓存一些TTL。 当为初始请求定义宽限期时,Varnish将缓存的对象保持在其TTL之外。 那段时间被称为“宽限期”。 如果后续请求是针对已过期但仍在其宽限期内的对象, 则 Varnish将返回陈旧的缓存对象, 同时执行异步后端请求 。 因此,只有初始请求会很慢。 客户将获得刷新请求,没有任何延迟。 基本上,您希望将“健康的后端宽限期”设置为后端生成响应所需的最长时间。 例: s ...
-
_futureCache字典基于uri密钥缓存Task 。 它会阻止您在请求网页时创建新Task ,而是返回上次请求uri时已创建的Task无论该Task是否已完成。 然后,对于该uri每个请求,调用代码等待相同的Task 。 如果已经完成,则立即返回该Task的结果。 如果没有,它会一直等到它完成。 无论如何,它只会获取一次页面。 The _futureCache dictionary is caching a Task based on a uri key. It is preventing you f ...
-
我不相信Azure在这方面对你做了什么。 这是您需要准确指定资源所需的缓存属性的问题。 使用WebAPI,您可以通过可通过myHttpResponseMessage.Headers.CacheControl属性访问的CacheControlHeaderValue来控制响应所具有的缓存属性。 假设你有一个像这样的控制器动作: public Foo Get(int id) { Foo myFoo = LoadSomeFooById(id); return myFoo; } 你需要做这样的事情 ...