为什么GET方法获取的网页代码比浏览器上面看到的代码少

sjjwind 2012-08-06 10:20:27

char sendBuff[200] = "GET http://blog.csdn.net/sjjwind HTTP/1.0\r\nHost:www.csdn.net\r\n\r\n";

这是我发送的字符串,但是返回的的却比浏览器上面的少好多,很明显的就是我接收到的没有中文说明,全是英文,而且上面的代码也比浏览器上面的少一些。
如果要接受像浏览器那么多的代码应该怎么写呢?
...全文
568 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
titer1 2012-08-08
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

好坑啊,我知道是什么原因了,我用的一个wprintf输出到文件的,谁知道在我这儿不能写unicode编码的,我的工程明明是Unicode的,一旦有汉字wprintf就不工作了,那次接受的包的数据也不会输出,结果在文件里面只留下了英文字符。我一直以为是转码的缘故。
[/Quote]

又见 微软的 宽字符问题,,这个真的很头疼
Gloveing 2012-08-07
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]
我确定是转码的问题了

C/C++ code

while(TRUE)
{
memset(pBuffer,0,1026);
nRet = recv(sock,pBuffer,1024,0);
if(nRet == 0 || nRet == SOCKET_ERROR)
{
break;……
[/Quote]
DWORD dwUnicodeLen = MultiByteToWideChar(CP_UTF8,0,pBuffer,-1,NULL,0 );//去掉试试
RLib 2012-08-07
  • 打赏
  • 举报
回复



http://blog.csdn.net/rrrfff/article/details/7787676 C++ UTF相关编码转换
http://rlib.googlecode.com/svn/RLib/RLib_Text.cpp 常见的转码方法
sjjwind 2012-08-07
  • 打赏
  • 举报
回复
我确定是转码的问题了

while(TRUE)
{
memset(pBuffer,0,1026);
nRet = recv(sock,pBuffer,1024,0);
if(nRet == 0 || nRet == SOCKET_ERROR)
{
break;
}
DWORD dwUnicodeLen = MultiByteToWideChar(CP_UTF8,0,pBuffer,-1,NULL,0 );
WCHAR* pwText = new WCHAR[dwUnicodeLen + 1];
memset(pwText,0,(dwUnicodeLen + 1) * sizeof(WCHAR));
if ( dwUnicodeLen > 0)
{
MultiByteToWideChar(CP_UTF8,0,pBuffer,-1,pwText,dwUnicodeLen);
}
wprintf(pwText);
}

我这么写的,但是一碰到汉字这个就转不了了,utf-8转unicode不是都这么转的么,求解。
sjjwind 2012-08-07
  • 打赏
  • 举报
回复
额。。这是写的别人的博客的名字。。
sjjwind 2012-08-07
  • 打赏
  • 举报
回复

HTTP/1.1 200 OK

Server: nginx/0.7.68

Date: Mon, 06 Aug 2012 23:41:21 GMT

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

Connection: close

Vary: Accept-Encoding

X-Powered-By: ASP.NET

Set-Cookie: uuid=c79666aa-2779-4dba-b893-3268957c6e14; expires=Tue, 07-Aug-2012 23:37:04 GMT; path=/

Cache-Control: public, no-store, max-age=60

Expires: Mon, 06 Aug 2012 23:38:04 GMT

Last-Modified: Mon, 06 Aug 2012 23:37:04 GMT

Vary: *

Content-Length: 44731



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>YHC@HC - s" type="text/javascript"></script>

<link rel="Stylesheet" type="text/css" href="http://static.blog.csdn.net/skin/ink/css/style.css" />

<link id="RSSLink" title="RSS" type="application/rss+xml" rel="alternate" href="/yhc13429826359/rss/list" />

<link rel="shortcut icon" href="/favicon.ico" />

<link type="text/css" rel="stylesheet" href="http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/default.css" />

</head>

<body>

<script src="http://csdnimg.cn/pubnav/js/pub_topnav_2011.js"type="text/javascript"></script>


<div id="container">

<div id="header">

<div class="header">

<div id="blog_title">

<h1><a href="/yhc13429826359">YHC@HC</a></h1>

<h2>no pain no gain</h2>

<div class="clear"></div>

</div>

<div class="clear"></div>

</div>

</div>

<div id="navigator">

<div class="navigator_bg"></div>

<div class="navigator">

<ul>

<li id="btnContents"><a href="?viewmode=contents"><span><img src="http: //static.blog.csdn.net/images/ico_list.gif"> target="_blank"><font color=red> easyUI 1.3 <div class="list_item article_item">

<div class="article_title">

<span class="ico ico_type_Original"></span>

<h3>

<span class="link_title"><a href="/yhc13429826359/article/details/7796033">

<font color="red">[/www.eclipse.org/mat/dow... </div>

<div class="article_manage">

<span class="link_postdate">2012-07-03 15:22</span>

<span class="link_view" title="t.application({
name: 'MyApp',
launch: function() {
Ext.create('Ext.container.Viewport', {
it... </div>

<div class="article_manage">

<span class="link_postdate">2012-08-06 17:29</span>

<span class="link_view" title="60;  // ption">

@author YHC

9826359/article/details/7834492">

easyUI SearchBox

</a></span>

</h3>

</div>



<div class="article_description">

@author YHC

ion">

@author YHC



<span class="link_title"><a href="/yhc13429826359/article/details/7834095">

easyUI Droppable

</a></span>

</h3>

</div>



<div class="article_description">

@author YHC

itle">

<span class="ico ico_type_Translated"></span>

<h3>

<span class="link_title"><a href="/yhc13429826359/article/details/7832169">

easyUI Draggable

</a></span>

</h3>

</div>



<div class="article_description">

@author YHC

le 


title
$('#dd').draggable({
handle:'#title'
});




easyloader.load('messager', function(){ // lated"></span>

<h3>

<span class="link_title"><a href="/yhc13429826359/article/details/7827685">

easyUI Tree

</a></span>

</h3>

</div>



<div class="article_description">

@author YHC

</div>

<div class="list_item article_item">

<div class="article_title">

<span class="ico ico_type_Translated"></span>

<h3>

<span class="link_title"><a href="/yhc13429826359/article/details/7827554">

easyUI PropertyGrid

</a></span>

</h3>

</div>



<div class="article_description">

@author YHC

aults

propertygrid

h3>

</div>



<div class="article_description">

@author YHC

<span class="ico ico_type_Translated"></span>

<h3>

<span class="link_title"><a href="/yhc13429826359/article/details/7825753">

easyUI Messager

</a></span>

</h3>

</div>



<div class="article_description">

@author YHC

</div>

<div class="list_item article_item">

<div class="article_title">

<span class="ico ico_type_Translated"></span>

<h3>

<span class="link_title"><a href="/yhc13429826359/article/details/7823702">

easyUI Dialog

</a></span>

</h3>

</div>



<div class="article_description">

@author YHC

"><a href="/yhc13429826359/article/details/7823702#comments" title="a href="/yhc13429826359/article/details/7823566" title="der 



<i... </div>

<div class="article_manage">

<span class="link_postdate">2012-08-02 16:11</span>

<span class="link_view" title="0;$.fn.numberspinner.defaults

numberspinner

alidatebox.defaults.<a href="/yhc13429826359/article/list/4">4</a> <a href="/yhc13429826359/article/list/5">5</a> <a href="/yhc13429826359/article/list/6">...</a> <a href="/yhc13429826359/article/list/2"></a>

<a href="http://my.csdn.net/my/letter/send/yhc13429826359" class="letter" title="[odeURIComponent(_blogger) + "?jsonpcallback=?";

$.getJSON(url, {}, function (data) {

if (data.succ == 1 && data.info == 1) {

$('#span_add_follow').attr('class', 'attented');

} else {

$('#span_add_follow').click(guanzhu);

}

}, 'json');

}

});

function guanzhu() {

var url = "http://my.csdn.net/index.php/follow/do_follow?jsonpcallback=?";

$.getJSON(url, { "username": _blogger }, function (data) {

if (data.succ == 1) {

alert(';|$)"));

if (m) return m[2];

else return '';

}

</script>



<div class="panel" id="panel_Search">

<ul class="panel_head"><span>div id="panel_Category" class="panel">

<ul class="panel_head"><span>icle/month/2012/06">2012articls" class="panel">

<ul class="panel_head"><span>/a><span>(786)</span>

</li>

<li>

<a href="/yhc13429826359/article/details/7434924" title="eclipse </span></ul>

<ul class="panel_body itemlist">

<li>

<a href="/yhc13429826359/article/details/7363723" title="JAVA," title="POI Excel 06
<li>

<a href="/yhc13429826359/article/details/7825753#comments">easyUI Messager</a>

<p style="margin:0px;">JohnnyDengy:

</p>

</li>

<li>

<a href="/yhc13429826359/article/details/7825753#comments">easyUI Messager</a>

<p style="margin:0px;">ligenhualear:

ipt type="text/javascript">document.write("<img src=http://counter.csdn.net/pv.aspx?id=26 border=0 width=0 height=0>");</script>



<script type="text/javascript" src="http://csdnimg.cn/pubfooter/js/publib_footer.js"></script>



<script type="text/javascript" src="http://www.csdn.net/ui/scripts/Csdn/counter.js"></script>







</div>

</body>

</html>

这是我接收到的
sjjwind 2012-08-07
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]
引用 5 楼 的回复:
我确定是转码的问题了

C/C++ code

while(TRUE)
{
memset(pBuffer,0,1026);
nRet = recv(sock,pBuffer,1024,0);
if(nRet == 0 || nRet == SOCKET_ERROR)
{
break;……

DWORD dwUnicodeLen = MultiByt……
[/Quote]
一般转都是获取长度,然后申请内存,最后转的吧
sjjwind 2012-08-07
  • 打赏
  • 举报
回复
好坑啊,我知道是什么原因了,我用的一个wprintf输出到文件的,谁知道在我这儿不能写unicode编码的,我的工程明明是Unicode的,一旦有汉字wprintf就不工作了,那次接受的包的数据也不会输出,结果在文件里面只留下了英文字符。我一直以为是转码的缘故。
mLee79 2012-08-07
  • 打赏
  • 举报
回复
试过 
GET /sjjwind HTTP/1.0
Host:blog.csdn.net

GET http://blog.csdn.net/sjjwind HTTP/1.0
Host:www.csdn.net

两个都没有问题, 收到的数据
Trying 117.79.93.222...
Connected to blog.csdn.net.
Escape character is '^]'.
HTTP/1.1 200 OK
Server: nginx/0.7.68
Date: Mon, 06 Aug 2012 17:16:05 GMT
Content-Type: text/html; charset=utf-8
Connection: close
Vary: Accept-Encoding
X-Powered-By: ASP.NET
Set-Cookie: uuid=6c66a321-8b34-4771-9ec1-e4d04955df32; expires=Tue, 07-Aug-2012 17:11:48 GMT; path=/
Cache-Control: public, no-store, max-age=60
Expires: Mon, 06 Aug 2012 17:12:48 GMT
Last-Modified: Mon, 06 Aug 2012 17:11:48 GMT
Vary: *
Content-Length: 12383

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>sjjwind的专栏 - 博客频道 - CSDN.NET</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
luciferisnotsatan 2012-08-07
  • 打赏
  • 举报
回复
浏览器-〉查看源代码,这个看到的才是这页代码内容。用浏览器直接看,是很多资源拼起来的页面。
luciferisnotsatan 2012-08-07
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

HTML code

HTTP/1.1 200 OK

Server: nginx/0.7.68

Date: Mon, 06 Aug 2012 23:41:21 GMT

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

Connection: close

Vary: Accept-Encoding

X-Powered-By: ASP.NET

Set-Co……
[/Quote]
最后不已经有 </html> ?
难道你是想看到那些a href等的内容?
Gloveing 2012-08-06
  • 打赏
  • 举报
回复
你完全接收完了没

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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