简体   繁体   English

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

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

I have a form with a host link and the url that i can post to. 我有一个带有主机链接和可以发布到的URL的表单。 The method works fine online, i want to use php to enter data automatically, how do i do so without curl 该方法在网上可以正常运行,我想使用php自动输入数据,如何做到不卷曲

it would be passed like this (Username, Password, Example, Example2) 它将像这样传递(用户名,密码,示例,Example2)

Example 2 is a string array of data with required parameter names 示例2是带有所需参数名称的数据的字符串数组

if there is nothing passed at all the error will state "Login Error" 如果根本没有传递任何错误,则错误将显示“登录错误”

if Example 2 is empty it will display "Root element is missing." 如果示例2为空,则会显示“缺少根元素”。

See also: How to post data in PHP using file_get_contents? 另请参阅: 如何使用file_get_contents在PHP中发布数据?

Basically you can use file_get_contents() and stream_context_create() for issuing a POST request. 基本上,您可以使用file_get_contents()stream_context_create()发出POST请求。 In your case: 在您的情况下:

$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);

Just open up a socket connection to port 80, send the headers (you can use livehttp headers if you want to cheat on creating the headers, just watch while posting from the browser and copy it). 只需打开与端口80的套接字连接,发送标头即可(如果您想欺骗创建标头,则可以使用livehttp标头,只需在浏览器中发布并复制它即可观看)。 Then send the data after the headers. 然后在标题之后发送数据。

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

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