http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 2696|回复: 4

[HttpHelper] 为什么post 文件不能用

[复制链接]
发表于 2014-12-1 15:11:17 | 显示全部楼层 |阅读模式
http://www.sufeinet.com/thread-9994-1-1.html
这是PHP代码
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
?>

C#
           string postfile = "C:\\Users\\admin\\Desktop\\POST.txt";
            //创建Httphelper对象
            http = new HttpHelper();
            //创建Httphelper参数对象
            item = new HttpItem()
            {
                URL = "http://localhost/1.php",//URL     必需项   
                Method = "post",//URL     可选项 默认为Get   
                ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值
                PostDataType = PostDataType.FilePath,
                Postdata = postfile
               


            };


返回的是PHP各种错误 用html文件来提交正常



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2016-8-5 15:15:02 | 显示全部楼层
首先你得贴出来一个错误信息看看,这个原因很复杂
 楼主| 发表于 2016-8-5 15:22:47 | 显示全部楼层
站长苏飞 发表于 2016-8-5 15:15
首先你得贴出来一个错误信息看看,这个原因很复杂

HTML返回结果
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: file in C:\wamp\www\1.php on line <i>2</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0003</td><td bgcolor='#eeeeec' align='right'>133200</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\1.php' bgcolor='#eeeeec'>..\1.php<b>:</b>0</td></tr>
</table></font>
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: file in C:\wamp\www\1.php on line <i>8</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0003</td><td bgcolor='#eeeeec' align='right'>133200</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\1.php' bgcolor='#eeeeec'>..\1.php<b>:</b>0</td></tr>
</table></font>
Upload: <br /><br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: file in C:\wamp\www\1.php on line <i>9</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0003</td><td bgcolor='#eeeeec' align='right'>133200</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\1.php' bgcolor='#eeeeec'>..\1.php<b>:</b>0</td></tr>
</table></font>
Type: <br /><br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: file in C:\wamp\www\1.php on line <i>10</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0003</td><td bgcolor='#eeeeec' align='right'>133200</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\1.php' bgcolor='#eeeeec'>..\1.php<b>:</b>0</td></tr>
</table></font>
Size: 0 Kb<br /><br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: file in C:\wamp\www\1.php on line <i>11</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0003</td><td bgcolor='#eeeeec' align='right'>133200</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\1.php' bgcolor='#eeeeec'>..\1.php<b>:</b>0</td></tr>
</table></font>
Stored in:  



正常的返回结果源码应该是:
Upload: POST.txt<br />Type: text/plain<br />Size: 0.6044921875 Kb<br />Stored in: C:\wamp\tmp\php5300.tmp

测试过程中感觉可能是post过去的时候post数据中 文件名不存在导致的
 楼主| 发表于 2016-8-5 15:28:20 | 显示全部楼层
Content-Type: multipart/form-data; boundary=---------------------------48213192825481
Content-Length: 909

-----------------------------48213192825481
Content-Disposition: form-data; name="file"; filename="POST.txt"
Content-Type: text/plain

内容隐藏
-----------------------------48213192825481
Content-Disposition: form-data; name="submit"

Submit
-----------------------------48213192825481--
 楼主| 发表于 2016-8-5 15:52:19 | 显示全部楼层
name="file"; 这里如果不是file 就会出问题
string dataFormat = boundary + "\r\nContent-Disposition: form-data; name=\"{0}\";filename=\"{1}\"\r\nContent-Type:application/octet-stream\r\n\r\n";

                string header = string.Format(dataFormat, "file", Path.GetFileName(file));
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-6-17 15:42

© 2014-2021

快速回复 返回顶部 返回列表