最近在做OCR增值税务处理时,接口是通过图片转base64提交处理然后返回数据的,我通过前端将图片转换为base64提交到后端接收时,通过在线工具进行测试,发现传递过去的数据可以使用,接收到的数据却提示损坏
将
<?php
header('Content-Type: text/html; charset=utf-8');
header('Access-Control-Allow-Origin: *'); // 允许任何网址请求
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE'); // 允许请求的类型
header('Access-Control-Allow-Credentials: true'); // 设置是否允许发送 cookies
header('Access-Control-Allow-Headers: Content-Type, Content-Length, Accept-Encoding, X-Requested-with, Origin'); // 设置允许自定义请求头的字段
// 接收POST数据
$base64=$_POST['base'];
替换为以下代码:
<?php
header('Content-Type: text/html; charset=utf-8');
header('Access-Control-Allow-Origin: *'); // 允许任何网址请求
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE'); // 允许请求的类型
header('Access-Control-Allow-Credentials: true'); // 设置是否允许发送 cookies
header('Access-Control-Allow-Headers: Content-Type, Content-Length, Accept-Encoding, X-Requested-with, Origin'); // 设置允许自定义请求头的字段
// 接收POST数据
$postData = file_get_contents('php://input');
$base64=urldecode($postData);
$new_base64 = substr($base64, 27);
即可解决
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有