php - Post/Get Request not sending parameters -
i trying send username , password through post request login page on localhost. using below code generate request , send page
$url='http://localhost/index.php'; $fields = array('username' => 'admin', 'password' => '1234'); curl_setopt($ch,curlopt_url,$url); curl_setopt($ch,curlopt_post,true); curl_setopt($ch,curlopt_postfields,http_build_query($fields)); curl_setopt($ch,curlopt_returntransfer,true); $result = curl_exec($ch); curl_close($ch); echo $result;
edit
print_r(curl_getinfo($ch)); prints information
array ( [url] => http://www.url.com/index.php [content_type] => text/html [http_code] => 200 [header_size] => 380 [request_size] => 182 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 2.234 [namelookup_time] => 0.063 [connect_time] => 0.063 [pretransfer_time] => 0.063 [size_upload] => 28 [size_download] => 2322 [speed_download] => 1039 [speed_upload] => 12 [download_content_length] => 2322 [upload_content_length] => 28 [starttransfer_time] => 2.234 [redirect_time] => 0 [certinfo] => array ( ) [primary_ip] => ::1 [primary_port] => 80 [local_ip] => ::1 [local_port] => 54953 [redirect_url] => ) array ( [host] => localhost [accept] => / [content-length] => 28 [content-type] => application/x-www-form-urlencoded )
the request generated , receive http 200, ok status response. request not sending parameters it, , in response receive normal login form instead of after login screen.
anyone please tell me wrong above code.
i have tried same stream_context_create , file_get_contents same reponse generated in both cases(login form instead of post login screen) receving parameters.
1) curlopt_post
option expect value of boolean
type. doesn't matter in code since count($fields)
casted true
if $fields
non-empty.
2) don't build post
data manually, use http_build_query()
instead. can pass array
of data curlopt_postfields
option , convert string
automatically .
3) don't need set content-type
header since curl set automatically post request.
Comments
Post a Comment