http 模拟请求_如何模拟长HTTP请求

http 模拟请求

It happens less frequently these days but there are times when we need to accommodate for a HTTP request timing out. The service could be down, under heavy traffic, or just poorly coded, or any host of other issues.

如今,这种情况的发生频率降低了,但是有时候我们需要适应HTTP请求超时。 服务可能会关闭,通信繁忙或只是编码不正确,或其他许多问题。

Whenever I need to simulate a long HTTP request, I use a bit of PHP to make it happen:

每当我需要模拟长HTTP请求时,我都会使用一些PHP来实现它:

<?php
        // Don't resolve this request for 5 seconds
        sleep(5);
        
        // A generic response
        echo 'This is the response!';

        // ... or hit a URL to make the case more realistic
        echo file_get_contents('https://website.tld/endpoint');
?>

With that script created, I make PHP start a server so I can make the request locally:

创建该脚本后,我使PHP启动服务器,以便可以在本地发出请求:

php -S localhost:8000

Now I can hit http://localhost:8000 and get the long request I want!

现在,我可以访问http://localhost:8000并得到我想要的长请求!

There are a number of ways you can accomplish these long form requests but this has always been a favorite of mine!

您可以通过多种方式来完成这些长格式请求,但这一直是我的最爱!

翻译自: https://davidwalsh.name/how-to-simulate-long-http-requests

http 模拟请求

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值