php中超级链接如何使用php post 数组参数方法传递参数

正文 通过URL参数post传递的实现方式 PHP/Javascript
通过URL参数post传递的实现方式 PHP/Javascript
发布时间: & 编辑:
jquery中文网为您提供通过URL参数post传递的实现方式 PHP/Javascript等资源,欢迎您收藏本站,我们将为您提供最新的通过URL参数post传递的实现方式 PHP/Javascript资源
&script&ec(2);&/script&
PHP实现方法在做接口,post传递方式,数据以字符串形式传输,返回数据用JSON封装。然后就开始各种测试啊。分享最终的方法:定义抓取函数:&pre class="brush:toolbar:false"&function&http_post_data($url,&$data_string)&{
&&&&$ch&=&curl_init();
&&&&curl_setopt($ch,&CURLOPT_POST,&1);
&&&&curl_setopt($ch,&CURLOPT_URL,&$url);
&&&&curl_setopt($ch,&CURLOPT_POSTFIELDS,&$data_string);
&&&&curl_setopt($ch,&CURLOPT_HTTPHEADER,&array(
&&&&&&&&'Content-Type:&application/&charset=utf-8',
&&&&&&&&'Content-Length:&'&.&strlen($data_string))
&&&&ob_start();
&&&&curl_exec($ch);
&&&&$return_content&=&ob_get_contents();
&&&&ob_end_clean();
&&&&$return_code&=&curl_getinfo($ch,&CURLINFO_HTTP_CODE);
&&&&return&array($return_code,&$return_content);
}&/pre&然后是方法:&pre class="brush:toolbar:false"&$url&&=&&路径&;
$data&=&array();&//数组
$data&=&json_encode($data);&&//转化为字符串
list($return_code,&$return_content)&=&http_post_data($url,&$data);
$return_content&=&json_decode($return_content,1);
var_dump($return_content);&//输出返回结果。&/pre&window.open url 参数post方式传递 最近在做web项目,碰到需要跨页面传递参数的功能,就是那种需要把当前页面的内容带到新开的子窗体中,以前的做法是传一个id过去,然后在新窗口中去读数据库的内容。虽然不怎么麻烦,但是如果内容么有在数据库里保存,仅仅是处以拟稿状态时,就不能实现了,用户还常常认为是个bug。考虑采用get的方式传递,把需要的内容都序列化然后,通过url去传,显得很臃肿,而且get的传递内容长度有限制。于是就想到用post的方式传递,问题在于open方法不能设置请求方式,一般网页的post都是通过form来实现的。如果仅仅模拟form的提交方式,那么open方法里那种可设置窗体属性的参数又不能用。最后想办法整了这么一个两者结合的方式,将form的target设置成和open的name参数一样的值,通过浏览器自动识别实现了将内容post到新窗口中。比较有意思的是直接通过调用form的submit方法不能触发onsubmit事件,查看了帮助文档,必须手动的触发,否则只能看到页面刷新而没有打开新窗口。代码中只传递了一个参数内容,实际可传递多个。具体代码如下:&pre class="brush:toolbar:false"&function&openPostWindow(url,name,data)&
&&&&var&tempForm&=&document.createElement(&form&);&
&&&&tempForm.id=&tempForm1&;&
&&&&tempForm.method=&post&;&
&&&&tempForm.action=&
&&&&tempForm.target=&
&&&&var&hideInput&=&document.createElement(&input&);&
&&&&hideInput.type=&hidden&;&
&&&&hideInput.name=&&content&
&&&&hideInput.value=&
&&&&tempForm.appendChild(hideInput);&&
&&&&tempForm.attachEvent(&onsubmit&,function(){&openWindow(name);&});
&&&&document.body.appendChild(tempForm);&
&&&&tempForm.fireEvent(&onsubmit&);
&&&&tempForm.submit();
&&&&document.body.removeChild(tempForm);
&&&&return&
function&openWindow(name)&
&&&&window.open('about:blank',name,'height=400,&width=400,&top=0,&left=0,&toolbar=yes,&menubar=yes,&scrollbars=yes,&resizable=yes,location=yes,&status=yes');&&
&/script&&/pre&调用:&pre class="brush:toolbar:false"&&A&href=&javascript:void(0);&&onClick=&openPostWindow('noWriteSiteInfo.jsp','noWriteSiteInfo','&%=lowerOffset&%&');&&
&&&这里是调用;&&
&&/A&&/pre&注意红色部分 如果没有这个,会导致页面上&jsp:include page=&&/& 这种页面丢失,这是 链接的href 和 onclick 共存问题,请求的链接是用的 A 标签,A上同时写了href和onclick事件。对于链接 A 标签而言,当用户鼠标单击的时候,A对象被触发时会首先去执行onclick部分,然后是href。解决方法就是:直接把onclick事件写在href中:href=&javascript:openPostWindow(。。。)&还有一种解决方案:&a href=&javascript:void(0)& onclick=&do();&&Test&/a&这样是忽略了href部分,这对于通过onclick传递this,或者无法避开a对象时都有用。您可能感兴趣的文章:PHP POST用法与说明_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
PHP POST用法与说明
&&POST用法与说明
阅读已结束,下载文档到电脑
想免费下载更多文档?
定制HR最喜欢的简历
你可能喜欢代码中使用curl方式上传数据到服务器,但我使用firebug和其他工具都没有抓取到发送的post参数信息,怎样才能抓取到post参数信息?
该问题被发起重新开启投票
投票剩余时间:
之前被关闭原因:
该问题被发起删除投票
投票剩余时间:
距离悬赏到期还有:
参与关闭投票者:
关闭原因:
该问题已经被锁定
锁定原因:()
保护原因:避免来自新用户不合宜或无意义的致谢、跟帖答案。
该问题已成功删除,仅对您可见,其他人不能够查看。
你的意思是说访问A,A中用CURL发送请求到B,然后你想获取这次请求中的POST参数吗?
如果是这样,那么这次请求,根本没有通过浏览器,你自然取不到的。(是A-B之间的交互)
var_dump($_POST);看下里面的结果里有没有你想要的POST参数。如果没有,有可能是你curl设置的参数有问题吧!
德问是一个专业的编程问答社区,请
后再提交答案
关注该问题的人
共被浏览 (2655) 次php发送post请求的三种方法
投稿:zxhpj
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了php发送post请求的三种方法,分别使用curl、file_get_content、fsocket来实现post提交数据,需要的朋友可以参考下
* 发送post请求
* @param string $url 请求地址
* @param array $post_data post键值对数据
* @return string
function send_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 $
//使用方法
$post_data = array(
&&'username' =& 'stclair2201',
&&'password' =& 'handan'
send_post('http://www.jb51.net', $post_data);
方法二:Socket版本
* Socket版本
* 使用方法:
* $post_string = "app=socket&version=beta";
* request_by_socket('', '/restServer.php', $post_string);
function request_by_socket($remote_server,$remote_path,$post_string,$port = 80,$timeout = 30) {
&&$socket = fsockopen($remote_server, $port, $errno, $errstr, $timeout);
&&if (!$socket) die("$errstr($errno)");
&&fwrite($socket, "POST $remote_path HTTP/1.0");
&&fwrite($socket, "User-Agent: Socket Example");
&&fwrite($socket, "HOST: $remote_server");
&&fwrite($socket, "Content-type: application/x-www-form-urlencoded");
&&fwrite($socket, "Content-length: " . (strlen($post_string) + 8) . "");
&&fwrite($socket, "Accept:*/*");
&&fwrite($socket, "");
&&fwrite($socket, "mypost=$post_string");
&&fwrite($socket, "");
&&$header = "";
&&while ($str = trim(fgets($socket, 4096))) {
&&&&$header .= $
&&$data = "";
&&while (!feof($socket)) {
&&&&$data .= fgets($socket, 4096);
&&return $
方法三:Curl版本
* Curl版本
* 使用方法:
* $post_string = "app=request&version=beta";
* request_by_curl('http://www.jb51.net/restServer.php', $post_string);
function request_by_curl($remote_server, $post_string) {
&&$ch = curl_init();
&&curl_setopt($ch, CURLOPT_URL, $remote_server);
&&curl_setopt($ch, CURLOPT_POSTFIELDS, 'mypost=' . $post_string);
&&curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
&&curl_setopt($ch, CURLOPT_USERAGENT, "jb51.net's CURL Example beta");
&&$data = curl_exec($ch);
&&curl_close($ch);
&&return $
下面是其他网友的方法:
class Request{
public static function post($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_
public static function post2($url, $data){//file_get_content
$postdata = http_build_query(
$opts = array('http' =&
'method' =& 'POST',
'header' =& 'Content-type: application/x-www-form-urlencoded',
'content' =& $postdata
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
public static function post3($host,$path,$query,$others=''){//fsocket
$post="POST $path HTTP/1.1\r\nHost: $host\r\n";
$post.="Content-type: application/x-www-form-";
$post.="urlencoded\r\n${others}";
$post.="User-Agent: Mozilla 4.0\r\nContent-length: ";
$post.=strlen($query)."\r\nConnection: close\r\n\r\n$query";
$h=fsockopen($host,80);
fwrite($h,$post);
for($a=0,$r='';!$a;){
$b=fread($h,8192);
$a=(($b=='')?1:0);
fclose($h);
return $r;
大家可以根据需要选择适合自己的即可。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具

我要回帖

更多关于 php 获取post参数 的文章

 

随机推荐