“Solicitação de postagem de envio do PHP” Respostas de código

Post PHP

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  Name: <input type="text" name="fname">
  <input type="submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  // do logic
  $name = $_POST['fname'];
}
?>
Andrew Lautenbach

Solicitação de postagem do PHP

$url = 'http://server.com/path';
$data = array('key1' => 'value1', 'key2' => 'value2');

// use key 'http' even if you send the request to https://...
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }

var_dump($result);
mountainpython

Postagem de recebimento do PHP

// Send data trough e.g. AJAX in JavaScript

$.ajax({
    type: "POST",
    url: 'example.php',
    data: { "num1": 1, "num2": 2},
    contentType: "application/json; charset=utf-8",
    dataType: "JSON",
    async: false
})

// You would receive it like this:
  
$num1 = $_POST["num1"];
$num2 = $_POST["num2"];

$sum = $num1 + $num2;
echo $sum;

// Would output: 3
Av3

Solicitação de postagem de envio do PHP

// CURL-less method with PHP5
$context  = stream_context_create(array(
  	// use key 'http' even if you send the request to https
    'http' => array(
      	//'header' and 'content' is optional
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query(
          array('key1' => 'value1', 'key2' => 'value2')
        )
    )
));
$result = file_get_contents('http://server.com/path', false, $context);
if ($result === FALSE) { 
	echo "an error occurred during post.";
    http_response_code(500);
} else {
  	// success
	var_dump($result);
}
try { hard = Coder(); }

Respostas semelhantes a “Solicitação de postagem de envio do PHP”

Perguntas semelhantes a “Solicitação de postagem de envio do PHP”

Mais respostas relacionadas para “Solicitação de postagem de envio do PHP” em PHP

Procure respostas de código populares por idioma

Procurar outros idiomas de código