当前位置:网站首页>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,用到再搜一搜更具体的内容。

边栏推荐
- 同花顺网上开户安全吗,需要注意什么
- 互联网技术发展内卷后的出路——iVX的诞生
- Actual combat | how to make a slam track truth acquisition device?
- Quartus call & Design d Trigger - simulation & time sequence Wave Verification
- Service stability governance
- White paper - Intel and Ashling, a well-known risc-v tool provider, strive to expand multi platform risc-v support
- 【课程预告】基于飞桨和OpenVINO 的AI表计产业解决方案 | 工业读表与字符检测
- windows 安装 MySQL
- AI reference kit
- . Net how to use log framework NLog
猜你喜欢

Go写文件的权限 WriteFile(filename, data, 0644)?

Linear regression analysis of parent-child height data set

白皮书丨英特尔携手知名RISC-V工具提供商Ashling,着力扩展多平台RISC-V支持

微信小程序之input前加图标

leetcode:42. Rain water connection

Detailed explanation of serial port, com, UART, TTL, RS232 (485) differences

Quartus II 13.1 detailed installation steps

Cloud native essay deep understanding of ingress

Generics, generic defects and application scenarios that 90% of people do not understand

Getting started with reverse debugging - learn about PE structure files
随机推荐
IEEE Transaction期刊修改过程记录
如何打开/关闭chrome控制台调试时的时间戳?
How do I turn on / off the timestamp when debugging the chrome console?
[Yunzhou said live room] - digital security special session will be officially launched tomorrow afternoon
人脸注册,解锁,响应,一网打尽
怎么手写vite插件
串口、COM、UART、TTL、RS232(485)区别详解
POW共识机制
64 channel telephone +2-channel Gigabit Ethernet 64 channel PCM telephone optical transceiver voice telephone to optical fiber
32-way telephone +2-way Gigabit Ethernet 32-way PCM telephone optical transceiver supports FXO port FXS voice telephone to optical fiber
Quartus call & design D trigger Simulation & timing wave verification
理解ADT与OOP
What are the conditions for a mature knowledge management?
实战监听Eureka client的缓存更新
2022 年以后,对AI开发人员意味着什么
leetcode:242. Valid Letter ectopic words
Cifar announces the second stage pan Canadian AI strategy
栈和队列的基本使用
如何正确计算导入Excel的行数(POI/NPOI)
Crmeb second open SMS function tutorial