http post in php without curl using username, pass

2019-06-11 06:46发布

I have a form with a host link and the url that i can post to. The method works fine online, i want to use php to enter data automatically, how do i do so without curl

it would be passed like this (Username, Password, Example, Example2)

Example 2 is a string array of data with required parameter names

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."

标签: php http post curl
2条回答
Root(大扎)
2楼-- · 2019-06-11 07:29

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). Then send the data after the headers.

查看更多
相关推荐>>
3楼-- · 2019-06-11 07:33

See also: How to post data in PHP using file_get_contents?

Basically you can use file_get_contents() and stream_context_create() for issuing a POST request. 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);
查看更多
登录 后发表回答