A. php 怎么POST获取数据
方法1、最常见的方法是:$_post['fieldname'];
说明:只能接收content-type:
application/x-www-form-urlencoded提交的数据
解释:也就是表单post过来的数据
方法2、file_get_contents("php://input");
说明:
允许读取
post
的原始数据。
和
$http_raw_post_data
比起来,它给内存带来的压力较小,并且不需要任何特殊的
php.ini
设置。
php://input
不能用于
enctype="multipart/form-data"。
解释:
对于未指定
content-type
的post数据,则可以使用file_get_contents(“php://input”);来获取原始数据。
事实上,用php接收post的任何数据都可以使用本方法。而不用考虑content-type,包括二进制文件流也可以。
所以用方法二是最保险的方法
B. 请教,php如何获取远程JSon内容 并post一些参数
$data = file_get_contents($url);//目的页面内容获取 $t = json_decode($data,1);//转换为PHP数组 //处理... $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $urlo);//数据发送地址 curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);//发送的数据数组 curl_exec($ch);
C. php如何上传图片到远程服务器
可以使用curl这个扩展来实现。
PHP 支持的由Daniel Stenberg创建的libcurl库允许你与各种的服务器使用各种类型的协议进行连接和通讯。
libcurl支持http、https、ftp、gopher、telnet、dict、file和ldap协议。libcurl同时也支持HTTPS认证、HTTP POST、HTTP PUT、 FTP 上传(这个也能通过PHP的FTP扩展完成)、HTTP 基于表单的上传、代理、cookies和用户名+密码的认证。
curl_close() 关闭一个cURL会话。
curl__handle()复制一个cURL句柄和它的所有选项。
curl_errno()返回最后一次的错误号。
curl_error()返回一个保护当前会话最近一次错误的字符串。
curl_escape()返回转义字符串,对给定的字符串进行URL编码。
curl_exec()执行一个cURL会话。
curl_file_create()创建一个CURLFile对象。
curl_getinfo()获取一个cURL连接资源句柄的信息。
curl_init()初始化一个cURL会话。
curl_multi_add_handle()向curl批处理会话中添加单独的curl句柄。
curl_multi_close()关闭一组cURL句柄。
curl_multi_exec()运行当前cURL句柄的子连接
curl_multi_getcontent()如果设置了CURLOPT_RETURNTRANSFER,则返回获取的输出的文本流。
curl_multi_info_read()获取当前解析的cURL的相关传输信息。
curl_multi_init()返回一个新cURL批处理句柄。
curl_multi_remove_handle()移除curl批处理句柄资源中的某个句柄资源。
curl_multi_select()等待所有cURL批处理中的活动连接。
curl_multi_setopt()设置一个批处理cURL传输选项。
curl_multi_strerror()返回描述错误码的字符串文本。
curl_pause()暂停及恢复连接。
curl_reset()重置libcurl的会话句柄的所有选项。
curl_setopt_array()为cURL传输会话批量设置选项。
curl_setopt()设置一个cURL传输选项。
curl_share_close()关闭cURL共享句柄。
curl_share_init()初始化cURL共享句柄。
curl_share_setopt()设置一个共享句柄的cURL传输选项。
curl_strerror()返回错误代码的字符串描述。
curl_unescape()解码URL编码后的字符串。
curl_version()获取cURL版本信息。
D. PHP的POST怎么用
表单提交一般有两种方式GET、POST。
POST方式的用法如下
代码例如:文件为index.php
html代码
<form name="biaodan" method="post" action="index.php?action=ok">
姓名:<input type="text" name="name" value="">
<br>
性别:<input type="text" name="sex" value="">
<br>
<input type="submit" value="提交">
</form>
php代码
<?php
if(isset($_GET['action']) && $_GET['action'] == 'ok'){
$name = $_POST['name'];
$sex = $_POST['sex'];
echo '姓名为:'.$name;
echo '<br>';
echo '性别为:'.$sex;
}
?>
E. 怎么用PHP发送POST请求
PHP发送POST请求的三种方式
classRequest{
publicstaticfunctionpost($url,$post_data='',$timeout=5){//curl
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,1);
if($post_data!=''){
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data);
}
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
curl_setopt($ch,CURLOPT_HEADER,false);
$file_contents=curl_exec($ch);
curl_close($ch);
return$file_contents;
}
publicstaticfunctionpost2($url,$data){//file_get_content$postdata=http_build_query(
$data
);$opts=array('http'=>
array(
'method'=>'POST',
'header'=>'Content-type:application/x-www-form-urlencoded',
'content'=>$postdata
)
);$context=stream_context_create($opts);
$result=file_get_contents($url,false,$context);
return$result;
}
publicstaticfunctionpost3($host,$path,$query,$others=''){//fsocket
$post="POST$pathHTTP/1.1 Host:$host ";
$post.="Content-type:application/x-www-form-";
$post.="urlencoded ${others}";
$post.="User-Agent:Mozilla4.0 Content-length:";
$post.=strlen($query)." Connection:close $query";
$h=fsockopen($host,80);
fwrite($h,$post);
for($a=0,$r='';!$a;){
$b=fread($h,8192);
$r.=$b;
$a=(($b=='')?1:0);
}
fclose($h);
return$r;
}
}
http://www.oschina.net/code/snippet_729516_33065
F. 如何用php向服务器发送post请求
用PHP向服务器发送HTTP的POST请求,代码如下:
<?php
/**
*发送post请求
*@paramstring$url请求地址
*@paramarray$post_datapost键值对数据
*@returnstring
*/
functionsend_post($url,$post_data){
$postdata=http_build_query($post_data);
$options=array(
'http'=>array(
'method'=>'POST',
'header'=>'Content-type:application/x-www-form-urlencoded',
'content'=>$postdata,
'timeout'=>15*60//超时时间(单位:s)
)
);
$context=stream_context_create($options);
$result=file_get_contents($url,false,$context);
return$result;
}
使用的时候直接调用上面定义的send_post方法:
$post_data=array(
'username'=>'username',
'password'=>'password'
);
send_post('网址',$post_data);
G. 用PHP怎么发送HTTP POST 请求。怎么获得返回结果。
传递? 用 form标签啊 <form action="" method="post"></form>
获取结果用超全局变量 $_post[]
H. php如何接收别的服务器post过来的数据 - 技术问答
通常情况下用户使用浏览器网页表单向服务器post提交数据,我们使用PHP的$_POST接收用户POST到服务器的数据,并进行适当的处理。但有些情况下,如用户使用客户端软件向服务端php程序发送post数据,而不能用$_POST来识别,那又该如何处理呢?
我们介绍php接受post数据的三种方式:
1.$_POST方式接收数据
$_POST方式是通过 HTTP POST 方法传递的变量组成的数组,是自动全局变量。如使用$_POST[‘name’]就可以接收到网页表单以及网页异步方式post过来的数据,
即$_POST只能接收文档类型为Content-Type: application/x-www-form-urlencoded提交的数据,也就是表单POST过来的数据。
2.$GLOBALS[‘HTTP_RAW_POST_DATA’]方式接收数据
但$GLOBALS[‘HTTP_RAW_POST_DATA’]中是否保存POST过来的数据取决于centent-Type的设置,只有在PHP在无法识别的Content-Type的情况下,才会将POST过来的数据原样地填入变量$GLOBALS[‘HTTP_RAW_POST_DATA’]中,像Content-Type=application/x-www-form-urlencoded时,该变量是空的。
另外,它同样无法读取Content-Type为multipart/form-data的POST数据,也需要设置php.ini中的always_populate_raw_post_data值为On,PHP才会总把POST数据填入变量$http_raw_post_data。
3.php://input方式接收数据
如果访问原始 POST 数据的更好方法是 php://input。php://input 允许读取 POST 的原始数据。和 $HTTP_RAW_POST_DATA 比起来,它给内存带来的压力较小,并且不需要任何特殊的php.ini设置,php://input不能用于 enctype=”multipart/form-data”。对于未指定 Content-Type 的POST数据,则可以使用file_get_contents(“php://input”)来获取原始数据。事实上,用PHP接收POST的任何数据都可以使用本方法。而不用考虑Content-Type,包括二进制文件流也可以。php://input读取不到$_GET数据。是因为$