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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 9122|回复: 5

[抓取] httphelper POST XML的时候会出问题,不知道什么原因

[复制链接]
发表于 2012-9-20 16:28:31 | 显示全部楼层 |阅读模式
代码如下:
[C#] 纯文本查看 复制代码
httphelper objhttp = new httphelper();
            objhttp.isToLower = false;
            HttpItem objHttpItem = new HttpItem();
            objHttpItem.URL="https://URL";
            objHttpItem.Method = "post";
            objHttpItem.ContentType = "text/xml";
            objHttpItem.Postdata=str;
            string rtnStr = objhttp.GetHtml(objHttpItem);


结果在类的53行出现错误:
未将对象引用设置到对象的实例。

但是我直接用下面的方法就不会:
[C#] 纯文本查看 复制代码
public string OpenReadWithHttps(string URL, string strPostdata, string strEncoding)
        {
            Encoding encoding = Encoding.Default;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
            request.Method = "post";
            request.Accept = "text/html, application/xhtml+xml, */*";
            request.ContentType = "text/xml";
            //request.ContentType = "application/x-www-form-urlencoded";
            byte[] buffer = encoding.GetBytes(strPostdata);
            request.ContentLength = buffer.Length;
            request.GetRequestStream().Write(buffer, 0, buffer.Length);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding(strEncoding)))
            {
                return reader.ReadToEnd();
            }
        }

不知是啥原因。



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2012-9-20 16:37:02 | 显示全部楼层
加个
[code=csharp]objHttpItem.Encoding = "UTF-8";[/code]
就可以了。
呵呵。
发表于 2012-9-20 16:51:40 | 显示全部楼层
可能是编码的问题,我记下这个Bug了,有时间优化一下,你这个其它是分析编码的问题,
加上编码就没有问题了。
发表于 2014-10-27 07:18:54 | 显示全部楼层
受教了学习中……
发表于 2016-3-31 17:10:23 | 显示全部楼层
没有解决这个问题
发表于 2016-4-1 08:06:48 | 显示全部楼层
解决也是另外一个帖子解决的!现在不知道新版本有无解决这个问题
解决是用网上的解决的
百度 post c# xml
问题出现时xml有中文的时候会乱码!提交不成功!
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-4-19 16:31

© 2014-2021

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