CURL 搞了 两天了 郁闷

tommycpma 2004-01-12 09:42:25
我要实现的功能 是 在一个网页里登陆 然后再到另外一个网页里POST一个文件上去
可是总是失败 以下是 我的源码 大家看看问题出在哪里?我很郁闷得说,对方使用JSP写的
<?php
$ch = curl_init();

$url= "http://61.135.142.6/sp/j_security_check";
$str="j_username=6_001&j_password=123456&submitbutton=登 录";
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,"1");
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);;
curl_setopt ($ch, CURLOPT_HEADER, 1);
$result = curl_exec($ch);


$url= "http://61.135.142.6/sp/component/spflow/modifyFlownum.do";
$str="flowId=6&flowName=6&ifShare=0&uploadFile=1&submitbutton=提 交";
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,"1");
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
$result = curl_exec($ch);
curl_close($ch);
?>
...全文
88 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoyuzi 2004-03-23
  • 打赏
  • 举报
回复
tommycpma 2004-01-18
  • 打赏
  • 举报
回复
UPUPUPUP:D
tommycpma 2004-01-14
  • 打赏
  • 举报
回复
再不行就只好看HTTP协议用SOCKET写了,痛哭中~~~~~~~~~~~~~~~~
xinchangpeng 2004-01-14
  • 打赏
  • 举报
回复
帮你顶
tommycpma 2004-01-14
  • 打赏
  • 举报
回复
当然加了扩展库 不然只会提示 找不到该函数亚
tommycpma 2004-01-13
  • 打赏
  • 举报
回复
还有 CURL 的中文资料太少了 英文的我又看不清爽 阵阵郁闷 大家介绍个 PHP 里的 CURL 的网址吧 英文的也成啊
tommycpma 2004-01-13
  • 打赏
  • 举报
回复
jackey() 的贴子我看过了 不可以得 单纯的POST数据很容易就实现了 问题是 现在你要POST数据的时候 需要登陆先 就是需要做两个POST过程 现在的问题是
1:我POST第一个页面,提示登陆成功 ,而向第二个页面POST数据的时候他提示我还没有登陆(这个我是用另外一个叫VBB的论坛测试的,因为我比较熟悉这个论坛)

2:http://61.135.142.6/sp这个地址的机制我不明白 大家直接把源代码拷贝执行一遍就能看到执行结果了 提示302错误 但是可能已经登陆成功,我不能肯定 为什么有的时候登陆成功,有的时候不成功 然后向第二页POST数据的时候,也是302错误 点击出来的连接 跳到了一个莫名其妙的地方 大家帮帮忙咯:)
indeed 2004-01-13
  • 打赏
  • 举报
回复
帮你顶顶
jackey 2004-01-13
  • 打赏
  • 举报
回复
如何从一个php文件向另一个地址post数据,不用表单和隐藏的变量
可以使用以下函数来实现:

function posttohost($url, $data) {
$url = parse_url($url);
if (!$url) return "couldn't parse url";
if (!isset($url['port'])) { $url['port'] = ""; }
if (!isset($url['query'])) { $url['query'] = ""; }

$encoded = "";

while (list($k,$v) = each($data)) {
$encoded .= ($encoded ? "&" : "");
$encoded .= rawurlencode($k)."=".rawurlencode($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)) {
$line = fgets($fp,1024);
if ($inheader && ($line == "\n" || $line == "\r\n")) {
$inheader = 0;
}
elseif (!$inheader) {
$results .= $line;
}
}
fclose($fp);

return $results;
}
?>


也可以这样


$URL="www.mysite.com/test.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://$URL");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "Data1=blah&Data2=blah");
curl_exec ($ch);
curl_close ($ch);
?>

多菜鸟 2004-01-13
  • 打赏
  • 举报
回复
up
microfire 2004-01-13
  • 打赏
  • 举报
回复
也许是忘了在 php.ini 里加入扩展库了吧

;extension=php_curl.dll
改成
extension=php_curl.dll
microfire 2004-01-13
  • 打赏
  • 举报
回复
http://curl.haxx.se/
tommycpma 2004-01-13
  • 打赏
  • 举报
回复
我自己UP

21,887

社区成员

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

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