高中生
最后登录1970-1-1
在线时间 小时
注册时间2013-6-21
|
我在以太网例子里修改了一下,尝试下载网页,好不容易能接受到数据了,但是后面接受到的数据有问题,而且lwip报错了。
我改的代码如下:
建立连接:
void TCP_Client_Init()
{
struct tcp_pcb *Clipcb;
struct ip_addr Mipaddr,Lipaddr;
IP4_ADDR(&Mipaddr,74,125,31,138); //谷歌ip
Clipcb = tcp_new(); // 建立通信的TCP控制块(Clipcb)
tcp_bind(Clipcb,IP_ADDR_ANY,1024); // 绑定本地IP地址和端口号
tcp_connect(Clipcb,&Mipaddr,80,TcpCli_Connected);
}
连接成功后:
err_t TcpCli_Connected(void *arg,struct tcp_pcb *pcb,err_t err)
{
tcp_write(pcb,TCP_TestData,sizeof(TCP_TestData),0)==ERR_OK;
tcp_recv(pcb,tcpcli_recv);
return ERR_OK;
}
接受数据:
static err_t tcpcli_recv(void *arg, struct tcp_pcb *pcb,struct pbuf *p,err_t err)
{
tcp_recved(pcb, p->tot_len);
printf(p->payload);
pbuf_free(p);
tcp_close(pcb);
return ERR_OK;
}
TCP_TestData 为:"GET / HTTP/1.1\r\nAccept-Encoding: gzip, deflate\r\nHost: 74.125.31.138\r\n\r\n"。
串口接受到的数据:
**************野火STM32_enc8j60+lwip移植实验*************
success 1
sucess 4
HTTP/1.1 200 OK
Date: Tue, 10 Dec 2013 09:43:41 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Set-Cookie: NID=67=GqzHbh4a0inK28OlD41NNas84jnsLIMue_7Tvx2QfupGphmgcdfcqXeERy3TA79UJpFt7nRiL0OpEqdpXhC1144vIPl9eFGZouTz6Q0Wbr615orqFJLROsS4d8CUjhRz; expires=Wed, 11-Jun-2014 09:43:41 GMT; path=/; domain=.; HttpOnly
P3P: CP="This is not a P3P policy! See http://www.google.com/support/ac ... n&answer=151657 for more info."
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alternate-Protocol: 80:quic
Transfer-Encoding: chunked
8000
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage"><head><meta itemprop="image" content="/images/google_favicon_128.png"><title>Google</title><script>(function(){
window.google={kEI:"TeKmUuK-Gc7OkQXDvYGoCg",getEI:function(a){for(var b;a&&(!a.getAttribute||!
Date).getTime();google.timers.load.t.iml=e;google.kCSI.imc=c;google.kCSI.imn=b;google.kCSI.imp=d;void
。。。。。。。。。。。。。。。。。。太长了省略中间部分。。。。。。。。。。。。。。。。。。。。。
0!==google.stt&&(google.kCSI.stt=google.stt);google.csiReport&&google.csiReport()}}window.addEventListener?window.addEventListener("load",n,!1):window.attachEvent&&window.attachEvent("onload",n);google.timers.load.t.prt=e=(new Date).getTime();})();
</script></body></html>
0
HTTP/1.0 400 Bad Request
Content-Type: text/html; charset=UTF-8
Content-Length: 925
Date: Tue, 10 Dec 2013 0
sucess 4
9:43:43 GMT
Server: GFE/2.0
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 400 (Bad Request)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 10020001864x no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}
</style>
<a href=//www.google.com/><img src=//www.google.com/images/errors/logo_sm.gif alt=Google></a>
<p><b>400.</b> <ins>That鈥檚 an error.</ins>
<p>Your client has issued a malformed or illegal request. <ins>That鈥檚 all we know.</ins>
gle.timers.load.t.iml=e;google.kCSI.imc=c;google.kCSI.imn=b;google.kCSI.imp=d;void 0!==google.stt&&(google.kCSI.stt=google.stt);google.csiReport&&google.csiReport()}}window.addEventListener?window.addEventListener("load",n,!1):window.attachEvent&&window.attachEvent("onload",n);google.timers.load.t.prt=e=(new Date).getTime();})();
</script></body></html>
0
HTTP/1.0 400 Bad Request
Content-Type: text/html; charset=UTF-8
Content-Length: 925
Date: Tue, 10 Dec 2013 0
sucess 4
H |
|