php 如何响应post的数据并给出一个返回值

javalele 2008-05-20 11:38:40
我有一个项目,客户要求将扫描数据库,将记录表中的各个公司的ID,名称,处理状态通过post发到一个url,这个url对应的php文件要求能处理post数据并返回一个response result(如verify,deny,not commit),我使用的post函数如下:
function do_post_request($id, $url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
//throw new Exception("Problem with $url, $php_errormsg");
$InfoSentLog="Problem with {$url}, remote system is down or internet is down";
$infosql="update personinfo set InfoSentLog='{$InfoSentLog}' where ID={$id}";
mysql_query($infosql);
return false;
}
$response = @stream_get_contents($fp);
if ($response === false) {
//throw new Exception("Problem reading data from $url, $php_errormsg");
$InfoSentLog="Problem reading data from {$url}, remote system is down or internet is down";
$infosql="update personinfo set InfoSentLog='{$InfoSentLog}' where ID={$id}";
mysql_query($infosql);
return false;
}
return $response;
}
}


其中,$response = @stream_get_contents($fp);就是得到服务器处理文件的返回值,如今我怎么写这个处理文件,即如何处理post数据并给一个返回值呢?请大虾们讲一下post响应并返回值的原理,最好有个简单的例子,谢谢!
...全文
1275 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
w2h2p2 2008-05-21
  • 打赏
  • 举报
回复
这样很不错啊
my_web 2008-05-21
  • 打赏
  • 举报
回复
自动跳转不好了嘛
fxs_2008 2008-05-21
  • 打赏
  • 举报
回复
用xmlhttp
或支持http1.1自定义的函数,用post方式上传,得到返回值分析就行了
具体搜索下php post 上传
  • 打赏
  • 举报
回复
mark

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧