奶头挺立呻吟高潮av全片,成人试看120秒体验区,性欧美极品v,A片高潮抽搐揉捏奶头视频

php語言

php中curlpost 時(shí)出現(xiàn)的問題解決

時(shí)間:2025-05-30 17:02:39 php語言 我要投稿
  • 相關(guān)推薦

php中curlpost 時(shí)出現(xiàn)的問題解決

  文章主要介紹了php curl post 時(shí)出現(xiàn)問題的解決方法,需要的朋友可以參考下,就跟隨百分網(wǎng)小編一起去了解下吧,想了解更多相關(guān)信息請(qǐng)持續(xù)關(guān)注我們應(yīng)屆畢業(yè)生考試網(wǎng)!

  在 a.php 中以 POST 方式向 b.php 提交數(shù)據(jù),但是 b.php 下就是無法接收到數(shù)據(jù),而 CURL 操作又顯示成功,非常詭異。原來,“傳遞一個(gè)數(shù)組到CURLOPT_POSTFIELDS,cURL會(huì)把數(shù)據(jù)編碼成 multipart/form-data,而然傳遞一個(gè)URL-encoded字符串時(shí),數(shù)據(jù)會(huì)被編碼成 application/x-www-form-urlencoded。

  ",而和我一樣對(duì) CURL 不太熟悉的人在編寫程序時(shí),代碼往往是下面的樣子:

  復(fù)制代碼 代碼如下:

  $data = array( 'Title' => $title, 'Content' => $content, 'ComeFrom' => $comefrom );

  curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);

  curl_setopt($ch, CURLOPT_URL, 'http://example.com/b.php');

  curl_setopt($ch, CURLOPT_POST, 1);

  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

  curl_exec($ch);

  也就是將所要提交的數(shù)據(jù)以數(shù)組的形式通過 POST 發(fā)送,而這樣就會(huì)導(dǎo)致 CURL 使用“錯(cuò)誤"的編碼“multipart/form-data",其效果相當(dāng)于我們直接以“<form method="post" action="b.php" enctype="multipart/form-data">"這樣的表單來完成操作,大家可以試試,這時(shí)的“b.php"是無論如何也無法通過 $_POST 來接收數(shù)據(jù)的。

  所以,正確的做法應(yīng)該是將上述范例代碼中的 $data 由數(shù)組變?yōu)榻?jīng) urlencode() 編碼后的

  【相關(guān)閱讀】

  php的curl實(shí)現(xiàn)get和post的代碼

  代碼實(shí)現(xiàn):

  1、http的get實(shí)現(xiàn)

  復(fù)制代碼 代碼如下:

  $ch = curl_init("http://www.jb51.net/") ;

  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ;

  curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ;

  $output = curl_exec($ch) ;

  $fh = fopen("out.html", 'w') ;

  fwrite($fh, $output) ;

  fclose($fh) ;

  2、http的post實(shí)現(xiàn)

  復(fù)制代碼 代碼如下:

  //extract data from the post

  extract($_POST) ;

  //set POST variables

  $url = 'http://www.jb51.net/get-post.php' ;

  $fields = array(

  'lname'=>urlencode($last_name) ,

  'fname'=>urlencode($first_name) ,

  'title'=>urlencode($title) ,

  'company'=>urlencode($institution) ,

  'age'=>urlencode($age) ,

  'email'=>urlencode($email) ,

  'phone'=>urlencode($phone)

  );

  //url-ify the data for the POST

  foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&' ; }

  rtrim($fields_string ,'&') ;

  //open connection

  $ch = curl_init() ;

  //set the url, number of POST vars, POST data

  curl_setopt($ch, CURLOPT_URL,$url) ;

  curl_setopt($ch, CURLOPT_POST,count($fields)) ;

  curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string) ;

  //execute post

  $result = curl_exec($ch) ;

  //close connection

  curl_close($ch) ;

【php中curlpost 時(shí)出現(xiàn)的問題解決】相關(guān)文章:

PHP中json-encode格式中文問題解決辦法02-16

PHP中的Trait03-29

出現(xiàn)頻率最高的PHP面試題02-03

PHP中php://input和$-POST的區(qū)別03-27

PHP中的魔術(shù)方法03-05

PHP中的Reload操作06-26

PHP中$-SERVER的詳解06-25

PHP中l(wèi)ist的方法07-05

PHP中的表單處理05-24

主站蜘蛛池模板: 泰来县| 左权县| 新邵县| 麟游县| 华亭县| 万年县| 黄骅市| 安义县| 青铜峡市| 万宁市| 道真| 胶州市| 库尔勒市| 宁化县| 柳州市| 商洛市| 大名县| 浙江省| 宁陵县| 黄龙县| 华池县| 邯郸市| 阳高县| 南平市| 鹿邑县| 忻城县| 革吉县| 措勤县| 河源市| 松滋市| 安陆市| 阿巴嘎旗| 西乌珠穆沁旗| 奉贤区| 文登市| 哈尔滨市| 宁河县| 博乐市| 华阴市| 望城县| 安吉县|