简体   繁体   English

如何在服务器端获取HTTPS发布请求的内容?

[英]How to get the content of a HTTPS post request on the server side?

I have a C client which use libcurl to send xml packet to Apache server via HTTPS. 我有一个C客户端,它使用libcurl通过HTTPS将xml数据包发送到Apache服务器。

some parts of the client code as: 客户端代码的某些部分为:

curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/test.php");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, send_buf);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(send_buf));
curl_easy_setopt(curl, CURLOPT_POST, 1L);
res = curl_easy_perform(curl);

The content of send_buf is sent to https apache server ( https://example.com/test.php ), but on the Apache server side, how can I use test.php to get the content of send_buf? send_buf的内容发送到https apache服务器( https://example.com/test.php ),但是在Apache服务器端,如何使用test.php获取send_buf的内容? Any other scripts are welcome. 任何其他脚本都欢迎。 thanks 谢谢

Any example codes? 任何示例代码?

I may be a little unclear on your question, but I'm assuming send_buf is in the standard format, ie, 我对您的问题可能不太清楚,但我假设send_buf为标准格式,即

foo=bar&baz=boo&x=17+cats+etc foo = bar&baz = boo&x = 17 + cats + etc

In that case, in your receiving PHP script (test.php) the $_POST variable will be initialized as follows: 在这种情况下,在您接收的PHP脚本(test.php)中,$ _POST变量将如下初始化:

$_POST['foo'] = "bar"
$_POST['baz'] = "boo"
$_POST['x'] = "17 cats etc"

So you can access a value by using $_POST['foo']. 因此,您可以使用$ _POST ['foo']访问值。

Hope that helps. 希望能有所帮助。

To get everything that is sent (POST) to your Apache server via your test.php file, you can use: 要获取通过test.php文件发送(POST)到Apache服务器的所有内容,可以使用:

<?php
    var_dump($_POST);
?>

You could also use $_GET if you wanted to get everything passed in the URL (like: https://example.com/test.php?myvar=value ). 如果您想让所有内容都通过URL传递,也可以使用$ _GET(例如: https : //example.com/test.php?myvar=value )。 Finally, $_REQUEST contains both $_POST and $_GET. 最后,$ _ REQUEST包含$ _POST和$ _GET。

If you post a variable called myvar via your C code, you can retrieve the value in your test.php file with: 如果通过C代码发布了名为myvar的变量,则可以使用以下方法在test.php文件中检索值:

<?php
    print $_POST['myvar'];
?>

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

相关问题 科尔多瓦:无法使用$ _POST在服务器端获取请求参数值 - Cordova: Can not get the request parameters values at server side using $_POST Android Volley POST请求:在服务器端获取GET请求方法(php) - Android Volley POST request: getting GET request method on server side (php) PHP ::获取POST请求内容 - PHP:: Get POST Request Content 发布请求在服务器端获取空值? - Post request getting null at server side? 取消HTTP POST请求服务器端 - Cancel an HTTP POST request server side PHP客户端向服务器端发送请求并向远程服务器发送服务器端请求 - PHP client post request to Server side and server side post request to remote server 如何通过翻新POST请求在PHP中提取服务器端的请求正文 - How to Extract Request Body at Server Side in PHP send by Retrofit POST request AJAX:jQuery DataTables(服务器端)没有获得任何请求(GET或POST)数据 - AJAX: jQuery DataTables (Server Side) not getting any request (GET or POST) data 如何在Cakephp中进行https发布请求 - How to make https post request in Cakephp 如何在排球库中发送jsonObject发布请求? 我在服务器端使用php - how to send jsonObject post request in volley library? am using php for the server side
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM