套接字和http的奇怪问题 [英] Strange problem with sockets and http

查看:104
本文介绍了套接字和http的奇怪问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

当我尝试使用套接字连接到服务器时遇到一个奇怪的问题:当我通过家庭网络进行连接时,它可以工作,但是当我通过学校的公共网络进行连接时,连接失败,这可能是您可能猜到的受监视.
我的代码:

Hi everyone!

I am having a strange problem when I try to connect to a server using a socket: It works when I do it from my home networks but it fails connecting when I do it from my school''s public network which is as you may guess monitored.
My code:

    WSASATA init;
    WSAStartup(MAKEWORD(2,2),&init);
SOCKET s=socket(AF_INET,SOCK_STREAM,0);

info.sin_family=AF_INET;
info.sin_addr.s_addr=inet_addr("209.85.227.147");   //Google''s IP address
info.sin_port=htons(80);
connect(s,(struct sockaddr*)&info,sizeof(info));

send(s,aEnvoyer.c_str(),aEnvoyer.size(),0);
    char resp[20001];
int nbcaractere=recv(serveur,resp,20000,0);
resp[nbcaractere]=''\0'';



其中aEnvoyer是包含有效GET请求的字符串.

学校可能正在阻塞这种插座.我知道那里不使用代理.

所以我的问题是:这段代码有问题吗?
我的第二个问题是:firefox和iexplore使用哪种类型的套接字才能与HTTP服务器通信?

非常感谢.
希望我很清楚,
Alban



Where aEnvoyer is a string containing a valid GET request.

The school may be blocking that kind of socket. I know that proxies are not used there.

So my question is: is this code problematic?
My second question is: What type of socket do firefox and iexplore use in order to communicate with HTTP servers?

Thank you very much.
Hoping I was clear,
Alban

推荐答案

1.这段代码很好.您的学校可能有阻止此类请求的防火墙.
2. HTTP在TCP上作为其传输层工作,因此浏览器使用操作系统提供给他们的传输层套接字.在Windows情况下为Winsock.
1. This code is fine. Your school might have a firewall that blocks such requests.
2. HTTP works on TCP as its transport layer, so browsers use the transport layer sockets made available to them by operating system. Which in windows case will be Winsock.


感谢您的答复.
您能告诉我如何使用这些传输层插槽吗?
实际上,我以为我已经在使用Winsock.我搜索此类信息已有一段时间,我尝试了一些示例,但没有一个起作用.谢谢!
Thank you for your reply.
Could you tell me how I can use these transport layer sockets?
In fact, I thought that I was already using Winsock. I''ve searched for that kind of info for a while, I tried some examples but none of them worked. Thanks!




我的猜测是您的学校正在使用透明的缓存代理.如果是这种情况,那么您实际上是在连接到代理服务器,例如 squid [浏览器标题 [
Hi,

My guess would be that your school is using a transparent caching proxy. If this is the case then you are actually connecting to a proxy server such as squid[^]. Squid can be configured to block fake browser requests by inspecting the browser headers.

I would suggest that you forge ALL of the browser headers[^] and I suspect you will have better success.

Best Wishes,
-David Delaune


这篇关于套接字和http的奇怪问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆