Created
August 4, 2016 15:27
-
-
Save aoktox/59c50085bd143ad09d4bdda89395fd99 to your computer and use it in GitHub Desktop.
CURL Send data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$post_data['email'] = '[email protected]'; | |
$post_data['password'] = 'password'; | |
//ubah array jadi data untuk posting (key1=value1) | |
foreach ( $post_data as $key => $value) { | |
$post_items[] = $key . '=' . $value; | |
} | |
//buat final string pake implode() | |
$post_string = implode ('&', $post_items); | |
//create cURL connection | |
$curl_connection = curl_init('https://proxy3.pens.ac.id:8443'); | |
//set options | |
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30); | |
curl_setopt($curl_connection, CURLOPT_USERAGENT, | |
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); | |
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); | |
//set data to be posted | |
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); | |
//perform our request | |
$result = curl_exec($curl_connection); | |
//show information regarding the request | |
//print_r(curl_getinfo($curl_connection)); | |
//echo curl_errno($curl_connection) . '-' . curl_error($curl_connection); | |
//echo curl_errno($curl_connection)."\n"; | |
if (curl_errno($curl_connection)=="0") { | |
echo "Sukses"."\n"; | |
}else{ | |
echo "Error : ".curl_error($curl_connection)."\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment