使用PHP发送自定义HTTP响应 [英] send custom HTTP response with PHP

查看:251
本文介绍了使用PHP发送自定义HTTP响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将自定义HTTP响应发送回请求GET到php脚本的应用程序.主体将采用二进制格式(八位字节流).我想知道是否有一个简单的方法来做到这一点?我正在研究PECL中的HttpResponse类,但现在无法安装它.我并不需要所有其他功能,因此我正在寻找更简单的方法.

I want to send a custom HTTP response back to an application requesting a GET to a php script. The body is will be in binary format (octet-streams). I'm wondering if there is a simple way to do this? I am looking into the HttpResponse class in PECL but is having trouble installing it right now. I do not really need all the other functionalities that goes with it so I'm looking for something simpler.

任何帮助将不胜感激.

推荐答案

PHP内置了header()函数,因此您可以自定义响应,而无需额外的库:

PHP has a header() function built in, so you can customise your response without requiring extra libraries:

<?php

header('Content-Type: application/octet-stream');
header('X-Powered-By: l3utterfly');

echo $binary_data;

?>

这篇关于使用PHP发送自定义HTTP响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆