首页 新闻 赞助 找找看

怎么解决火狐工具poster发送get请求,出现乱码

0
[已解决问题] 解决于 2014-07-08 10:42


<title>�ٶ�--���ķ��ʳ�����</title>
<style type="text/css">
body{margin:0;padding:0;font-size:14px;font-family:"����",Arial, Helvetica, sans-serif;}
img,ul,li,form,h2,ol{border:0;padding:0;margin:0;list-style:none;}
.cl{clear:both;height:0px;line-height:0px;font-size:0px;overflow:hidden;}
input{vertical-align:middle;}
a:link{color:#0033cc}
a:visited{color:#800080;}
a:hover{color:#800080;}
a:actived{color:#800080;}
#content{width:95%;align:center;margin:0 auto 0;}
.logo{float:left;width:141px;margin:10px 0 0 0;}
.title{float:right;width:;line-height:24px;background:#e5ecf9;margin:20px 0 0 0;padding-left:8px;}
.title a{margin-left:320px;}
.tip{font-size:18px;margin:25px 0 25px 5px;*margin:25px 0 25px 5px;}
.reason{margin:25px 0 33px 5px;*margin:25px 0 30px 5px;}
.reason li{line-height:24px;height:24px;}
.searchbox{margin:0 0 40px 8px;*margin:0 0 40px 8px;}
.help{margin:0 0 100px 5px;}
.footer{margin:50px 0 20px 0;*margin:50px 0 20px 0;text-0%">
<tr bgcolor="#e5ecf9">
<td height="24">&nbsp;<b class="p1">���ķ��ʳ�����</b></td>
<td class="p2" height="24"><div align="right"><a href="http://www.baidu.com/">�ٶ���ҳ</a> | <a href="http://www.baidu.com/search/jiqiao.html">��������</a> &nbsp;</div></td>
</tr>
<tr><td class="p2" height="20" colspan="2"></td></tr>
</table>
</td>
</tr>
</table>
<div id="content">
<h2 class="tip" style="padding-left:144px"><p>�ܱ�Ǹ����Ҫ���ʵ�ҳ�治����!<br><br></p><hr color="#dddddd" size="1"></h2>
</div>
<div id="content">
<ol class="reason" style="padding-left:144px">
<li> 1. ���������ʵ���ַ�Ƿ���ȷ��</li><br>
<li> 2. ���������ȷ�Ϸ��ʵ���ַ�������<a href="http://www.baidu.com/more/index.html">�ٶȸ���</a>ҳ��鿴������ַ��</li><br>
<li> 3. ֱ������Ҫ���ҵ����ݣ�</li>
<li class="searchbox"><br>
<form action="http://www.baidu.com/s" name="f">
<input type="text" name="wd" size="35" maxlength="100"><input type="hidden" name="cl" value="3"><input type="hidden" name="tn" value="baiduerr"><input 

 

{"status":0,"size":1,"total":1,"pois":[{"title":"\u5927\u6e05\u82b1","location":[116.321984,40.043131],"city":"\u5317\u4eac\u5e02","create_time":"2014-07-07 10:54:34","geotable_id":70699,"address":"\u5927\u6e05\u82b111","province":"\u5317\u4eac\u5e02","district":"\u6d77\u6dc0\u533a","city_id":131,"id":334995104}],"message":"\u6210\u529f"}

 

get
问题补充:

上面那些代码我是用poster工具得出的

 

之后我就在vs中写代码,处理请求类是这样写的

  public static string SendRequest(string url)
        {
            string data = string.Empty;
            WebRequest wreq = null;
            WebResponse wrep = null;
            Stream stream = null;
            StreamReader reader = null;
            try
            {
                wreq = WebRequest.Create(url);
                wrep = wreq.GetResponse();
                stream = wrep.GetResponseStream();
                reader = new StreamReader(stream, System.Text.Encoding.UTF8);
                data = reader.ReadToEnd();
            }
            catch (Exception)
            {
                //throw;
            }
            finally
            {
                if (reader != null) reader.Dispose();
                if (stream != null) stream.Dispose();
                //if (wrep != null) wrep.Dispose();
                if (wreq != null) wreq.Abort();
            }
            return data;
        }
View Code

但是,得出结果,还是跟上面的那样

福气满满好运连连的主页 福气满满好运连连 | 初学一级 | 园豆:60
提问于:2014-07-07 14:42
< >
分享
最佳答案
0

Content-Type: text/html; charset=utf-8

奖励园豆:5
Launcher | 高人七级 |园豆:45045 | 2014-07-07 14:50

俺之前就已经在这里添加过了,还是木有用啊

之前添加过了

福气满满好运连连 | 园豆:60 (初学一级) | 2014-07-07 15:12

@魔女小溪: 不是请求,是响应,看你提问中的截图。

你给的截图中显示出的乱码是在记事本中打开看到的吗?

Launcher | 园豆:45045 (高人七级) | 2014-07-07 15:17

@魔女小溪: 用 Fiddler 抓个包,在 HexView 中把 <title>�ٶ�--���ķ��ʳ�����</title> 的 Hex 值给贴出来。

Launcher | 园豆:45045 (高人七级) | 2014-07-07 15:20

@Launcher: 不是,是火狐poster工具,点击get弹出来的结果

福气满满好运连连 | 园豆:60 (初学一级) | 2014-07-07 15:25

@魔女小溪: 很有可能返回的中文使用的是 GB2312 编码,而你的 poster 工具只能识别 ASCII,UTF-16,UTF-8.

Launcher | 园豆:45045 (高人七级) | 2014-07-07 15:26

@Launcher: 

大哥,我想问下,在程序里面怎么转换这个呀?

 

public static string SendRequest(string url) { string data = string.Empty; WebRequest wreq = null; WebResponse wrep = null; Stream stream = null; StreamReader reader = null; try { wreq = WebRequest.Create(url); wrep = wreq.GetResponse(); stream = wrep.GetResponseStream(); reader = new StreamReader(stream, System.Text.Encoding.UTF8); data = reader.ReadToEnd(); } catch (Exception) { //throw; } finally { if (reader != null) reader.Dispose(); if (stream != null) stream.Dispose(); //if (wrep != null) wrep.Dispose(); if (wreq != null) wreq.Abort(); } return data; }

 

就是这段代码呀?我进行的是post操作,但是,获取到的也是那种乱码

福气满满好运连连 | 园豆:60 (初学一级) | 2014-07-07 15:28

@魔女小溪: 

new StreamReader(stream, System.Text.Encoding.GetEncoding("GB2312")); 试试

Launcher | 园豆:45045 (高人七级) | 2014-07-07 15:28

@Launcher: 好

福气满满好运连连 | 园豆:60 (初学一级) | 2014-07-07 15:29

@Launcher: 转换过来了。O(∩_∩)O~,3q,只是是出错的信息,(⊙o⊙)…

福气满满好运连连 | 园豆:60 (初学一级) | 2014-07-07 15:33

@Launcher: 大哥,为啥我用

 public static string CreateGeoTable(string name, int geotype, int is_published, string ak)
        {

            string url = "http://api.map.baidu.com/geodata/v3/geotable/create ?name="
               + name + "&ak=" + ak + "&is_published=" + is_published + "&geotype=" + geotype;
            return NetworkHelper.SendRequest(url);
        }
View Code

我用代码去创建表,就会报错

<!DOCTYPE html>
<html>
<head>
<meta charset="gbk">
<title>百度--您的访问出错了</title>
<style type="text/css">
    body{margin:0;padding:0;font-size:14px;font-family:"宋体",Arial, Helvetica, sans-serif;}
    img,ul,li,form,h2,ol{border:0;padding:0;margin:0;list-style:none;}
    .cl{clear:both;height:0px;line-height:0px;font-size:0px;overflow:hidden;}
    input{vertical-align:middle;}
    a:link{color:#0033cc}
    a:visited{color:#800080;}
    a:hover{color:#800080;}
    a:actived{color:#800080;}
    #content{width:95%;align:center;margin:0 auto  0;}
    .logo{float:left;width:141px;margin:10px 0 0 0;}
    .title{float:right;width:;line-height:24px;background:#e5ecf9;margin:20px 0 0 0;padding-left:8px;}
    .title a{margin-left:320px;}
    .tip{font-size:18px;margin:25px 0 25px 5px;*margin:25px 0 25px 5px;}
    .reason{margin:25px 0 33px 5px;*margin:25px 0 30px 5px;}
    .reason li{line-height:24px;height:24px;}
    .searchbox{margin:0 0 40px 8px;*margin:0 0 40px 8px;}
    .help{margin:0 0 100px 5px;}
    .footer{margin:50px 0 20px 0;*margin:50px 0 20px 0;text-align:center;color:#666666;}
    .footer a{color:#666666;}
</style>
</head>
<body>
<table border="0" width="95%" align="center">
    <tr height="60">
        <td height="65" valign="top" width="141"><a href="http://www.baidu.com/"><img border="0" src="http://www.baidu.com/search/img/logo.gif" alt="到百度首页" /></a></td>
        <td valign="bottom">
            <table border="0" cellspacing="0" cellpadding="0" width="100%">
                <tr bgcolor="#e5ecf9">
                    <td height="24">&nbsp;<b class="p1">您的访问出错了</b></td>
                    <td class="p2" height="24"><div align="right"><a href="http://www.baidu.com/">百度首页</a>  |  <a href="http://www.baidu.com/search/jiqiao.html">帮助中心</a> &nbsp;</div></td>
                </tr>
                <tr><td class="p2" height="20" colspan="2"></td></tr>
            </table>
        </td>
    </tr>
</table>
<div id="content">
    <h2 class="tip" style="padding-left:144px"><p>很抱歉,您要访问的页面不存在!<br><br></p><hr color="#dddddd" size="1"></h2>
</div>
<div id="content">
<ol class="reason" style="padding-left:144px">
        <li> 1. 请检查您访问的网址是否正确。</li><br>
        <li> 2. 如果您不能确认访问的网址,请浏览<a href="http://www.baidu.com/more/index.html">百度更多</a>页面查看更多网址。</li><br>
        <li> 3. 直接搜索要查找的内容:</li>
    <li class="searchbox"><br>
        <form action="http://www.baidu.com/s" name="f">
            <input type="text" name="wd" size="35" maxlength="100"><input type="hidden" name="cl" value="3"><input type="hidden" name="tn" value="baiduerr"><input type="submit" value="百度一下">
      </form></li>
    <li class="help">
      4.如有任何意见或建议,请及时<a href="http://qingting.baidu.com/">反馈给我们</a><br><br><br>
        <b>推荐您访问:</b><a href="http://news.baidu.com/">新闻</a> <a href="http://tieba.baidu.com/">贴吧</a> <a href="http://zhidao.baidu.com/">知道</a> <a href="http://music.baidu.com/">音乐</a> <a href="http://image.baidu.com/">图片</a> <a href="http://video.baidu.com/">视频</a> <a href="http://map.baidu.com/">地图</a> <a href="http://baike.baidu.com/">百科</a> <a href="http://wenku.baidu.com/">文库</a> <a href="http://www.hao123.com/">hao123</a>
    </li> </ol>

    <div class="footer">&#169; 2014 Baidu&nbsp;<a href="http://www.baidu.com/duty/index.html">免责声明</a></div>
</div>
</body>
</html>
错误
福气满满好运连连 | 园豆:60 (初学一级) | 2014-07-07 15:59

@魔女小溪: 是 GET 请求吧。

string url = "http://api.map.baidu.com/geodata/v3/geotable/create ?name="
               + name + "&ak=" + ak + "&is_published=" + is_published + "&geotype=" + geotype;

 

是不是多了个空格啊? 你把生成的 url 输入到 IE 地址栏中试试。

Launcher | 园豆:45045 (高人七级) | 2014-07-07 16:03

@Launcher: 不是,是post请求

福气满满好运连连 | 园豆:60 (初学一级) | 2014-07-07 16:06

@Launcher: (*^__^*) 嘻嘻……,貌似确实多了个空格,我滴个神那,我肿么可以这么粗心

福气满满好运连连 | 园豆:60 (初学一级) | 2014-07-07 16:07

@魔女小溪: 

你是要 post 到 http://api.map.baidu.com/geodata/v3/geotable/create,还是 post 到

http://api.map.baidu.com/geodata/v3/geotable/create ?name="
               + name + "&ak=" + ak + "&is_published=" + is_published + "&geotype=" + geotype ?

Launcher | 园豆:45045 (高人七级) | 2014-07-07 16:08

@Launcher: 

posthttp://api.map.baidu.com/geodata/v3/geotable/create ?name="
               + name + "&ak=" + ak + "&is_published=" + is_published + "&geotype=" + geotype

福气满满好运连连 | 园豆:60 (初学一级) | 2014-07-07 16:08

@魔女小溪:  uri 错了,多了个空格,去掉试试。

Launcher | 园豆:45045 (高人七级) | 2014-07-07 16:09

@Launcher: 恩恩,已经改过来了,但是,又出错了

{"status":3,"message":"http method\u9519\u8bef"}  我查了一下错误码,意思是http method错误

是不是以get的方式提交了呀,我是把

http://api.map.baidu.com/geodata/v3/geotable/create ?name="
               + name + "&ak=" + ak + "&is_published=" + is_published + "&geotype=" + geotype ?

这东东,放到一个也是要通过post提交方式的借口里面

  public string StartTourist(string id, string lat, string lng)
        {

                //var client = visitorClientService.GetList().Where(e => e.DeviceToken == id).FirstOrDefault();
                //if (client == null)
            //{
            #region 存入数据库
                    if (lat==null||lng==null)
                    {
                        return "没有数据";
                    }
                    var client = new Domain.Entity.VisitorClient();
                    client.AddTime = System.DateTime.Now;
                    client.IpAddress = "127.0.0.1";
                    client.SortNum = 0;
                    client.State = true;
                    client.DeviceToken = id;

                    //经度
                    client.Longitude = lng;

                    //纬度
                    client.Latitude = lat;
                    visitorClientService.Add(client, this.SessionUser());
            #endregion
            #region 存入百度LBS云
            string ak = "zirgBM8o5Wq5FpgjnozhVlNz";
            int geotype = 1;
            int is_published = 1;
            int geotable_id = 0;
            string name = "VisitorClient";
            string result = CreateGeoTable(name,geotype,is_published,ak);
            
            
                    
                    
            #endregion
                    // }
                //else
                //{
                //        client.Latitude = lat;
                //        client.Longitude = lng;
                //        client.AddTime = System.DateTime.Now;
                //        visitorClientService.Modify(client, userService.GetDefautlOperUser());
                   
                //}
           // return new EmptyResult();
                return lat + lng;
        }
View Code
福气满满好运连连 | 园豆:60 (初学一级) | 2014-07-07 16:12

@魔女小溪: 对不起,是 GET 还是 POST,URI 的格式是什么样子,Content 应该怎么写,我不知道,你问百度开发这个服务的人去。

Launcher | 园豆:45045 (高人七级) | 2014-07-07 16:14

@Launcher: 

哦,O(∩_∩)O~,谢谢

福气满满好运连连 | 园豆:60 (初学一级) | 2014-07-07 16:29

@Launcher: (⊙o⊙)…,真心觉得我笨死了,我写的就是一个get的请求。。。

福气满满好运连连 | 园豆:60 (初学一级) | 2014-07-07 16:39
其他回答(2)
0

所以说还是用谷歌浏览器好啊

吴瑞祥 | 园豆:29449 (高人七级) | 2014-07-07 15:26

我也想下载postman,可是,打不开谷歌呀!

支持(0) 反对(0) 福气满满好运连连 | 园豆:60 (初学一级) | 2014-07-07 15:30

我这里用火狐的poster插件没有乱码问题

支持(0) 反对(0) vicyang | 园豆:204 (菜鸟二级) | 2014-07-07 15:36
0

reader = new StreamReader(stream, System.Text.Encoding.UTF8); 这里编码格式改下试试
另外你请求的URL是啥 方便发出来吗

丫的 | 园豆:1575 (小虾三级) | 2014-07-07 15:32

这个不行的,呵呵,

System.Text.Encoding.GetEncoding("GB2312"),这个才行

支持(0) 反对(0) 福气满满好运连连 | 园豆:60 (初学一级) | 2014-07-07 15:38

@魔女小溪: 恩 国内很多都是gb2312

支持(0) 反对(0) 丫的 | 园豆:1575 (小虾三级) | 2014-07-07 15:39

@魔女小溪: 

我是想要在百度lbs云上面创建表

http://api.map.baidu.com/geodata/v3/geotable/create ?name=Visitor&ak=zirgBM8o5Wq5FpgjnozhVlNz&is_published=1&geotype=1

但是,出错了

支持(0) 反对(0) 福气满满好运连连 | 园豆:60 (初学一级) | 2014-07-07 15:50

@魔女小溪: 没有这个页面呢  跳转到了http://www.baidu.com/search/error.html这个页面..这个页面是gbk编码的..

reader = new StreamReader(stream, System.Text.Encoding.GetEncoding("gbk"))

支持(0) 反对(0) 丫的 | 园豆:1575 (小虾三级) | 2014-07-07 15:58

@tomcat1988: 哦,那我试试,希望成功![坏笑]

支持(0) 反对(0) 福气满满好运连连 | 园豆:60 (初学一级) | 2014-07-07 16:02

@魔女小溪: 出现新的错误了,O(∩_∩)O哈哈~,继续解决。。

支持(0) 反对(0) 福气满满好运连连 | 园豆:60 (初学一级) | 2014-07-07 16:12
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册