Heim  >  Artikel  >  Backend-Entwicklung  >  Teilen Sie zwei Methoden zur Simulation der POST-Datenübertragung in PHP

Teilen Sie zwei Methoden zur Simulation der POST-Datenübertragung in PHP

高洛峰
高洛峰Original
2016-11-30 13:56:531114Durchsuche

方法1 
复制代码 代码如下: 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "http://192.168.1.135/turntable/get_jump.php"); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $array); 
curl_exec($ch); 
curl_close($ch); 

方法2 
复制代码 代码如下: 
$data['uid'] = $this->uid; 
$data['efforts'] = $res['efforts']; 
$data['breakthrough'] = $res['breakthrough']; 
$data['target'] = $res['target']; 
$str = ''; 
foreach ($data as $k=>$v) { 
if (is_array($v)) { 
foreach ($v as $kv => $vv) { 
$ str .= '&' . $k . '[' . $kv . ']=' . URL-Code($vv); 

} else { 
$str .= '&' . $k . '=' . URL-Code($v); 


$context = 
array('http' => 
array('method' => 'POST', 
'header' => ' Inhaltstyp: application/x-www-form-urlencoded'."rn". 
'User-Agent: Manyou API PHP Client 0.1 (non-curl) '.phpversion()."rn". 'Inhaltslänge: ' . strlen($str), 
'content' => 
$contextid = stream_context_create($context); 
$sock = fopen('http://192.168.1.135/turntable/get_jump.php', 'r', false, $contextid); 
if ($sock) { 
$result = ''; 
while (!feof($sock)) { 
$result .= fgets($sock, 4096); 

fclose($sock); 

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn