当前位置:首页 » 编程语言 » php发送http请求

php发送http请求

发布时间: 2023-06-05 01:51:24

⑴ 求助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);

⑵ php怎么响应客户端发送http请求

http请求有get,post。
php发送http请求有三种方式[我所知道的有三种,有其他的告诉我]。
1. file_get_contents();详情见:http://www.jb51.net/article/41833.htm
2. curl发送请求。
3. fsocket发送。
下面说使用curl发送。
首先环境需要配置好curl组件。
在windows中让php支持curl比较简单:
在php.ini中将extension=php_curl.dll前面的分号去掉,
有人说需要将php根目录的libeay32.dll和ssleay32.dll需要拷贝到系统目录下去。我实验不拷贝也可以。
linux中,如果使用源码安装,需要在make 之前,./configure --with-curl=path,
其中,path是你的 libcurl库的位置,比如你安装libcurl库之后,
path可能就是/usr/local/,libcurl可以是静态库,也可以是动态库。
注意libcurl库configure的时候,可以将一些不需要的功能去掉,
比如ssl , ldap等。在php configure的时候,会去检查libcurl中某些功能是否被开启,进而去相应地调整生成的php。

⑶ php如何通过get方法发送http请求,并且得到返回的参数

1. 可以用curl函数或fsockopen() 与其他服务器通讯。当然也可以用file_get_contents() 简单一些但是有时候不好用。
2. 对方服务器返回json或xml,或简单的字符串
具体使用自己学习一下吧。

⑷ PHP 模拟HTTP发送POST请求

用php模拟登陆主要分为三部分1. post数据。2.根据返回的http头,从中截出cookie段。3.伪造http头发送请求。 我这里以用php抓取163相册的需要密码才能访问的目录为例。<?phpfunction posttohost($url, $data) //post数据if (!isset($url['query'])) $encoded = "";foreach ($data as $k=>$v) $fp = fsockopen($url['host'], $url['port'] ? $url['port'] : 80);if (!$fp) return "Failed to open socket to $url[host]";fputs($fp, sprintf("POST %s%s%s HTTP/1.0\n", $url['path'], $url['query'] ? "?" : "", $url['query']));fputs($fp, "Host: $url[host]\n");fputs($fp, "Content-type: application/x-www-form-urlencoded\n");fputs($fp, "Content-length: " . strlen($encoded) . "\n");fputs($fp, "Connection: close\n\n");fputs($fp, "$encoded\n");$line = fgets($fp,1024);if (!eregi("^HTTP/1\.. 200", $line)) return;$results = ""; $inheader = 1;while(!feof($fp)) elseif ($inheader) }fclose($fp);return $results;} 答案补充 function getjs($juser,$jaid,$jcookie) //伪造http头 答案补充 else fclose( $socket ); return $ret;}}$iurl=' http://photo.163.com/photos/'.$iuser.'/'.$aid.'/';$idata=array ('pass'=>$pass,'checking'=>'1'); //通过winsock抓包发现,输入访问密码,会向163相册发送 pass=密码&checking=1$mystr=posttohost($iurl,$idata);$pattern='/HALFORDER=(.*?);/';preg_match($pattern,$mystr,$out);$str=getjs($iuser,$aid,$out[1]);echo $str;?>

⑸ 怎么用PHP发送HTTP请求

var_loader:URLloader;
_loader=newURLLoader();
//建立事件的侦听

configureListeners(_loader);
//建立urlloader的数据

varloaderData:URLVariables=newURLVariables();
loaderData.userName="kidliu";
loaderData.passWord="123456";
//建立请求地址

varurl:String="localhost/login.php";

varrequest:URLRequest=newURLRequest(url);

//把数据和请求邦定

request.data=loaderData;
//设定请求的方式

request.method=URLRequestMethod.POST;

try{

_loader.load(request);

}catch(error:Error){

trace(error);

}
(dispatcher:IEventDispatcher):void{

//加载完成事件;

dispatcher.addEventListener(Event.COMPLETE,loaderHandler);

//开始访问事件;

dispatcher.addEventListener(Event.OPEN,loaderHandler);

//加载进度事件;

dispatcher.addEventListener(ProgressEvent.PROGRESS,loaderHandler);

//跨域访问安全策略事件;

dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR,loaderHandler);

//Http状态事件;

dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS,loaderHandler);

//访问出错事件;

dispatcher.addEventListener(IOErrorEvent.IO_ERROR,loaderHandler);

}
privatefunctionloaderHandler(event:*):void

{

switch(event.type){

caseEvent.COMPLETE:

trace("成功:"+_loader.data);

break;

caseEvent.OPEN:

trace("open:"+event);

break;

caseProgressEvent.PROGRESS:

trace("progress:"+event);

break;

caseSecurityErrorEvent.SECURITY_ERROR:

trace("securityError:"+event);

热点内容
mp4反编译软件 发布:2024-10-25 16:47:33 浏览:998
哪个是提升电脑帧数的配置 发布:2024-10-25 16:43:45 浏览:95
以一种访问权限不允许的方式 发布:2024-10-25 16:38:32 浏览:404
嵌入式linux开发环境搭建 发布:2024-10-25 16:26:51 浏览:325
奥迪a4l乞丐版什么配置 发布:2024-10-25 16:20:33 浏览:411
python读取txt文件数据 发布:2024-10-25 16:07:36 浏览:23
获取局域网服务器的真实ip 发布:2024-10-25 16:01:36 浏览:28
多线程程序java 发布:2024-10-25 15:58:32 浏览:228
安卓最大的图片是哪个 发布:2024-10-25 15:55:06 浏览:467
云服务器登录小号 发布:2024-10-25 15:41:34 浏览:402