Helpco
جمعه 08 بهمن 1395, 06:49 صبح
سلام چطوری میشه این کد را در سی شارپ استفاده کرد؟
$url = 'http://www.example.com/mywebpage';$data = array( 'username' => 'YourEmail', 'url' => 'http://www.example.com/mywebpage', );
//Function 1 , without curlfunction httpPost_nocurl($url, $data) { $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencodedrn", 'method' => 'POST', 'content' => http_build_query($data) ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); return $result;}
//Function 2 , with curlfunction httpPost_curl($url, $data){ $curl = curl_init($url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); curl_close($curl); return $response;}
echo httpPost_curl($url, $data);
$url = 'http://www.example.com/mywebpage';$data = array( 'username' => 'YourEmail', 'url' => 'http://www.example.com/mywebpage', );
//Function 1 , without curlfunction httpPost_nocurl($url, $data) { $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencodedrn", 'method' => 'POST', 'content' => http_build_query($data) ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); return $result;}
//Function 2 , with curlfunction httpPost_curl($url, $data){ $curl = curl_init($url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); curl_close($curl); return $response;}
echo httpPost_curl($url, $data);