简体   繁体   English

POST请求后如何获取页面正文

[英]How to get page body after POST request

I'm trying to make a PHP page that lets you upload a document to telegram servers and than retrives a file_id which is stored in the json of the redirect page.我正在尝试制作一个 PHP 页面,让您可以将文档上传到电报服务器,然后检索存储在重定向页面的 json 中的 file_id。 After some tutorials on YT this is the code:在 YT 上的一些教程之后,这是代码:

<?php
    $botToken = "1099xxxxxx:AxxxE-g9qDI2Uxxxxxxxxxxxxxxxxxxxxxxxx";
    $website = "https://api.telegram.org/bot".$botToken;
?>

<form action="<?php echo $website.'/sendPhoto' ?>" method="post" enctype="multipart/form-data">
    <input type="text" name="chat_id" value="mychatid">
    <input type="file" name="photo">
    <input type="submit" value="send">
</form>

Redirect after submit提交后重定向

The goal is to retrive the file_id of the file and save it in a variable, possibly without opening another tab.目标是检索文件的 file_id 并将其保存在变量中,可能无需打开另一个选项卡。

Thanks!谢谢!

You've making the request to the Telegram API from the browser by submitting a form directly to it.您已经通过直接向浏览器提交表单向 Telegram API 发出请求。

There is no way your PHP can get any information from that API that way.您的 PHP 无法以这种方式从该 API 获取任何信息。

As a side effect, you are giving your token (which should be kept secret) to every visitor who uses the form.作为副作用,您将您的令牌(应保密)提供给使用该表单的每个访问者。

You need the browser to submit the form to a PHP program you control and then make the request to the Telegram API from your PHP and not from the browser.您需要浏览器将表单提交给您控制的 PHP 程序,然后从您的 PHP而不是从浏览器向 Telegram API 发出请求。

The usual way to do this is with the cURL library .通常的方法是使用cURL 库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM