繁体   English   中英

PHP中的http帖子没有使用用户名,密码,param1,param2(字符串数组)的curl?

[英]http post in php without curl using username, password, param1, param2(string array)?

我有一个带有主机链接和可以发布到的URL的表单。 该方法在网上可以正常运行,我想使用php自动输入数据,如何做到不卷曲

它将像这样传递(用户名,密码,示例,Example2)

示例2是带有所需参数名称的数据的字符串数组

如果根本没有传递任何错误,则错误将显示“登录错误”

如果示例2为空,则会显示“缺少根元素”。

另请参阅: 如何使用file_get_contents在PHP中发布数据?

基本上,您可以使用file_get_contents()stream_context_create()发出POST请求。 在您的情况下:

$post = http_build_query(array(
    "username" => "user",
    "password" => "pw",
    "example" => "...",
));

$context = stream_context_create(array("http"=>array(
     "method" => "POST",
     "header" => "Content-Type: application/x-www-form-urlencoded\r\n" .
                 "Content-Length: ". strlen($post) . "\r\n",  
     "content" => $post,
))); 

$page = file_get_contents("http://example.com/login", false, $context);

只需打开与端口80的套接字连接,发送标头即可(如果您想欺骗创建标头,则可以使用livehttp标头,只需在浏览器中发布并复制它即可观看)。 然后在标题之后发送数据。

暂无
暂无

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

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