当前位置: 技术问答>linux和unix
发送http的问题
来源: 互联网 发布时间:2015-08-26
本文导语: 向一网页发送http请求后经常会收不到response返回的数据 如:Response.Write("hello") 经常收不到"hello"串,收的内容如下: 100 Continue Server: Microsoft-IIS/5.1 Date: Tue, 14 Dec 2004 03:55:13 GMT X-Powered-By: ASP.NET 正常收到结果时是这...
向一网页发送http请求后经常会收不到response返回的数据
如:Response.Write("hello")
经常收不到"hello"串,收的内容如下:
100 Continue
Server: Microsoft-IIS/5.1
Date: Tue, 14 Dec 2004 03:55:13 GMT
X-Powered-By: ASP.NET
正常收到结果时是这样的:
100 Continue
Server: Microsoft-IIS/5.1
Date: Tue, 14 Dec 2004 03:59:16 GMT
X-Powered-By: ASP.NET
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Tue, 14 Dec 2004 03:59:16 GMT
X-Powered-By: ASP.NET
Connection: close
Content-Length:13
Content-Type:text/html;Charset=gb2312
Set-Cookie:ASPSESSIONIDQGGQGPFO=IDBFEOCDIEKKLDDCOKGBMOKG;path=/
Cache-control:private
hello
问:(1)为什么会经常收不到后面的信息
(2) 收到正确的信息后该如何去掉http头协议信息,比如我只想要hello这样的数据
程序代码片段如下:
/***************************************************************
[function] :send remote server a http request
[input ] :
[out ] :
CCT_GOOD 1 successful
CCT_BAD 0 failed
***************************************************************/
CCT_RETCODE SendHttpRequest(char *sendbuf,int timeout,CCT_RES *res)
{
SOCKET sockfd;
int nbytes,httpid;
char buffer[1024];
char buf1[1024];
int http_len;
char http_pkg[1024];
int i=0;
int real_recv_len=0;
int data_left=0;
char *rec_buf;
struct timeval interval;
fd_set fs;
portnumber=80;
memset(buffer,0,1024);
memset(http_pkg,0,1024);
#if(os==windows)
{
WSAData ws;
WSAStartup(2,&ws);
}
#endif
if((host=gethostbyname(hostname))==NULL)
{
printf("get hostname errorn");
return CCT_BAD;
}
if((sockfd=socket(AF_INET,SOCK_STREAM,0))==-1)
{
printf("Socket Error:%san",errno);
return CCT_BAD;
}
while(sockfd
如:Response.Write("hello")
经常收不到"hello"串,收的内容如下:
100 Continue
Server: Microsoft-IIS/5.1
Date: Tue, 14 Dec 2004 03:55:13 GMT
X-Powered-By: ASP.NET
正常收到结果时是这样的:
100 Continue
Server: Microsoft-IIS/5.1
Date: Tue, 14 Dec 2004 03:59:16 GMT
X-Powered-By: ASP.NET
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Tue, 14 Dec 2004 03:59:16 GMT
X-Powered-By: ASP.NET
Connection: close
Content-Length:13
Content-Type:text/html;Charset=gb2312
Set-Cookie:ASPSESSIONIDQGGQGPFO=IDBFEOCDIEKKLDDCOKGBMOKG;path=/
Cache-control:private
hello
问:(1)为什么会经常收不到后面的信息
(2) 收到正确的信息后该如何去掉http头协议信息,比如我只想要hello这样的数据
程序代码片段如下:
/***************************************************************
[function] :send remote server a http request
[input ] :
[out ] :
CCT_GOOD 1 successful
CCT_BAD 0 failed
***************************************************************/
CCT_RETCODE SendHttpRequest(char *sendbuf,int timeout,CCT_RES *res)
{
SOCKET sockfd;
int nbytes,httpid;
char buffer[1024];
char buf1[1024];
int http_len;
char http_pkg[1024];
int i=0;
int real_recv_len=0;
int data_left=0;
char *rec_buf;
struct timeval interval;
fd_set fs;
portnumber=80;
memset(buffer,0,1024);
memset(http_pkg,0,1024);
#if(os==windows)
{
WSAData ws;
WSAStartup(2,&ws);
}
#endif
if((host=gethostbyname(hostname))==NULL)
{
printf("get hostname errorn");
return CCT_BAD;
}
if((sockfd=socket(AF_INET,SOCK_STREAM,0))==-1)
{
printf("Socket Error:%san",errno);
return CCT_BAD;
}
while(sockfd