当前位置:网站首页>php接收和发送数据
php接收和发送数据
2022-06-23 13:13:00 【qq_45911550】
写在前面:看此文之前,希望读者有一些php的基础,还需要知道搭建网站的一些知识
客户端通常通过url去访问服务器,服务器接收到客户端的请求之后将客户端需要的数据返回给客户端,这里自然会产生两个问题:
1、服务器如何接收客户端发送的请求
建立一个php文件,命名为welcome.php,里面写入内容
欢迎 <?php echo $_REQUEST["fname"]; ?>!<br>
你的年龄是 <?php echo $_REQUEST["age"]; ?> 岁。
在网站根目录下建立一个文件夹为minipro,将这个文件放在该文件夹下
然后你通过浏览器访问连接http://127.0.0.1/minipro/welcome.php?fname=ericzeng&age=2
结果如下:
到此就实现了数据的接收
2、服务器如何将数据返回给客户端,客户端是如何接收的
这里我曾经也很迷惑,后来发现只需要一个echo足矣,看下面的例子:
我们使用微信小程序来向本地服务器发送请求(需要设置一下,在设置->项目设置->勾选不校验合法域名https啥的,不然能对本地服务器发起请求)
小程序文件信息如下:
index.js
Page({
data: {
t:"haode"
},
onLoad: function () {
this.setData({
t:"hello world!"});
wx.request(
{
url:"http://127.0.0.1/minipro/welcome.php?fname=ericzeng&age=2",
headers:{
'content-type':'application/json'
},
method:'GET',
success:res=>{
this.setData({
t:res.data
})
}
}
);
}
})
index.wxml
<view>
<view>{
{
t}}</view>
</view>
我们依然访问之前的链接,会发现网页上的数据出现在了小程序页面上,只需要在本地处理一下数据格式就ok了,当然数据我们一般以json格式来进行传送,在php中使用json_encode()方法可以将数据转换为json,用到再搜一搜更具体的内容。

边栏推荐
- 通过 OpenVINO Model Server和 TensorFlow Serving简化部署
- Actual combat | how to make a slam track truth acquisition device?
- Overview of national parks in the United States
- Broadcast level E1 to aes-ebu audio codec E1 to stereo audio XLR codec
- 使用OpenVINOTM预处理API进一步提升YOLOv5推理性能
- pyqt5之designer制作表格
- What does it mean for AI developers after 2022
- 理解ADT与OOP
- 逆向调试入门-了解PE结构文件
- 父母-子女身高数据集的线性回归分析
猜你喜欢

栈和队列的基本使用

Germancreditdata of dataset: a detailed introduction to the introduction, download and use of germancreditdata dataset

90%的人都不懂的泛型,泛型的缺陷和应用场景

Windows install MySQL

OpenVINOTM 2022.1中AUTO插件和自动批处理的最佳实践

你管这破玩意儿叫 MQ?

How to correctly calculate the number of rows imported into EXCEL (poi/npoi)

16 channel HD-SDI optical transceiver multi channel HD-SDI HD video optical transceiver 16 channel 3g-sdi HD audio video optical transceiver

逆向调试入门-了解PE结构文件

Gradle Build Cache引发的Task缓存编译问题怎么解决
随机推荐
通过 OpenVINO Model Server和 TensorFlow Serving简化部署
理解ADT与OOP
pyqt5之designer制作表格
面向 PyTorch* 的英特尔 扩展助力加速 PyTorch
Architecture design methods in technical practice
Principle analysis of three methods for exchanging two numbers
Deci 和英特尔如何在 MLPerf 上实现高达 16.8 倍的吞吐量提升和 +1.74% 的准确性提升
互联网技术发展内卷后的出路——iVX的诞生
Restcloud ETL resolves shell script parameterization
Windows install MySQL
The redis keys command should be used with caution in the production environment. It is best to shield it
Develop a powerful tool for increasing efficiency - vscode plug-in sharing in 2022
Former amd chip architect roast said that the cancellation of K12 processor project was because amd counseled!
How do I turn on / off the timestamp when debugging the chrome console?
同花顺网上开户安全吗,需要注意什么
Oracle中dbms_output.put_line怎么使用
sed -i命令怎么使用
Generics, generic defects and application scenarios that 90% of people do not understand
Overview of national parks in the United States
Digraph D and e