Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php执行特定的HTTP POST_Php_Forms_Http_Curl_Post - Fatal编程技术网

使用php执行特定的HTTP POST

使用php执行特定的HTTP POST,php,forms,http,curl,post,Php,Forms,Http,Curl,Post,我想使用php执行特定的HTTP post(是的,这与其他线程不同)。 因此,一个名为的url有一个表单post,我想使用php执行它。 看起来是这样的: <form action="." method="post" enctype="multipart/form-data"> 提交按钮如下所示 <input type="submit" name="Okay" value="Okay"> 表单中填充了各种输入,如RemoteAddress和LocalPort。

我想使用php执行特定的HTTP post(是的,这与其他线程不同)。 因此,一个名为的url有一个表单post,我想使用php执行它。 看起来是这样的:

<form action="." method="post" enctype="multipart/form-data">

提交按钮如下所示

<input type="submit" name="Okay" value="Okay">

表单中填充了各种输入,如RemoteAddress和LocalPort。我尝试了这段代码来执行post,但是代码怎么知道我要执行哪个特定的表单呢?提交文件的名称为“OK”。我应该把这些信息放在哪里

<?php
$url = 'http://127.0.0.1:8060/PFOOptions/?PFOID=0x0000004C98FFBDD0';
$data = array('LocalPort' => '2743', 'RemoteAdress' => 'halo.com');

// 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);
?>

我错过了什么

代码如何知道我要执行哪个特定表单

一般来说:它不能

HTML表单与该表单的用户输入相结合,告诉浏览器如何构造HTTP请求

当您编写PHP来发出HTTP请求时,需要编写PHP来代替表单和用户输入


提交文件的名称为“OK”。我应该把这些信息放在哪里

<?php
$url = 'http://127.0.0.1:8060/PFOOptions/?PFOID=0x0000004C98FFBDD0';
$data = array('LocalPort' => '2743', 'RemoteAdress' => 'halo.com');

// 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);
?>
提交按钮(如果用于提交表单)将其名称和值添加到提交的表单数据中,就像任何其他表单控件一样

因此,您将其放在表单数据其余部分的相同位置

i、 e.分配给
$data


我错过了什么

您正在以
应用程序/x-www-form-urlencoded
格式构建数据

您还指定了内容类型应为
application/x-www-form-urlencoded

但是,这些匹配很好,表单显示
enctype=“multipart/form data”
,因此您提交的URL可能不支持
application/x-www-form-urlencoded
输入,您需要这样做



根据您提供的信息,我们可能还无法确定其他事实,例如出于身份验证目的对cookie的期望。

非常感谢。但是如果我想指定submit按钮,比如name=“Okay”,我应该将该值设置为什么?所以它知道这是我想要执行的。另外,您知道我应该用什么替换这个应用程序/x-www-form-urlencoded?@Karldrakar-提交按钮的值。请参阅链接问题-请记住,您需要将数据编码为多部分,而不仅仅是更改内容类型以声明它是多部分。