Click here to Skip to main content
15,915,093 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: + cannot add two pointers, most elegant solution ? [modified] Pin
Alain Rist29-Oct-10 20:44
Alain Rist29-Oct-10 20:44 
QuestionStandard way to implement plain text and binary input/output methods Pin
Skippums29-Oct-10 15:28
Skippums29-Oct-10 15:28 
Questionproblem related to "Nural networks face detection algprithm" Pin
inayathussaintoori29-Oct-10 15:15
inayathussaintoori29-Oct-10 15:15 
AnswerRe: problem related to "Nural networks face detection algprithm" Pin
Richard MacCutchan29-Oct-10 22:38
mveRichard MacCutchan29-Oct-10 22:38 
Questionfatal error LNK1168: cannot open file.exe for writing under Windows 7 VS 2008 Pin
transoft29-Oct-10 12:05
transoft29-Oct-10 12:05 
QuestionRe: fatal error LNK1168: cannot open file.exe for writing under Windows 7 VS 2008 Pin
David Crow29-Oct-10 16:16
David Crow29-Oct-10 16:16 
AnswerRe: fatal error LNK1168: cannot open file.exe for writing under Windows 7 VS 2008 [modified] Pin
transoft29-Oct-10 18:33
transoft29-Oct-10 18:33 
QuestionUsing WIN32 to Web server to send request,how to remove the HTTP response header Information! Pin
badwei29-Oct-10 4:48
badwei29-Oct-10 4:48 
I hope to use a Socket to a Web server to send request, and then obtain Web server respond to my data. But in the response data inside, there is always a response head, how should I get rid of the response head. I tried by the response data length to intercept head off response head data, but I failed, because of different response, data different lengths. How should I do?

#include <stdio.h>
#include <winsock2.h>
#pragma comment(lib,"WS2_32")


//package the http head message ,
void PacketSocket(const char *host,const char *url,const char *data,char *reBuf)
{
	//write the string to reBuf
	wsprintf(reBuf,"POST %s HTTP/1.1\r\nAccept:text/html\r\nAccept-Language:zh-cn,en\r\nAccept-Encoding:gzip,deflate\r\nContent-type:application/x-www-form-urlencoded\r\nAccept-Charset:GBK\r\nHost:%s\r\nContent-Length:%d\r\nContent-Encoding:utf-8\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; (R1 1.3))\r\nConnection:Keep-Alive\r\nSet-Cookie:JSESSIONID=193F85DD5F193A5714CBC5246218ECO3\r\n\r\n%s",url,host,strlen(data),data);
}

int main(){

	WSADATA wsa;
	WORD version=MAKEWORD(1,1);
	
	//start up the WSASocket
	if(WSAStartup(version,&wsa)==SOCKET_ERROR){
		printf("start error!");
		return -1;
	}


	SOCKET s;

	//server address
	sockaddr_in addr;


	s=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
	if(s==INVALID_SOCKET)
	{
		printf("has a error,the code:%d",GetLastError());
		return -1;
	}

	//I  have established a J2EE WEB server, and  then start it,
	//use the socket to send request to get index.jsp page
	addr.sin_addr.S_un.S_addr=inet_addr("127.0.0.1");
	addr.sin_port=htons(8080);//the port is 8080  --j2ee web server
	addr.sin_family=AF_INET;

	//connection  the server
	if(connect(s,(sockaddr*)&addr,sizeof(addr))==SOCKET_ERROR){
		printf("connect had an error!");
		return -1;
	}
	char szData[1024];//request data 

	//Encapsulation request message,I've built a socket j2ee project
	PacketSocket("localhost","/socket/index.jsp","start=0&limit=15",szData);

	if(send(s,szData,strlen(szData),0)==SOCKET_ERROR){ //To the server sends request
		printf("send request had an error!");
		return -1;
	}
	char szRecv[1024];//Receiving the return value

	int nCount=recv(s,szRecv,1024,0);
	if(nCount>0)
	{
		szRecv[nCount]='\0';
		printf("%s",szRecv);
	}

	WSACleanup();
	return 0;
}


Response data as follows

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=0910F038DEBB2C62C41C53A4E30C1C00; Path=/socket
Content-Type: text/html;charset=ISO-8859-1
Content-Length: 582
Date: Fri, 29 Oct 2010 14:45:46 GMT


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Hello,Win32 socket!</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<body>
Receiving request, then this page response to the client
</body>
</html>
Press any key to continue


How do I get from response data removing the following data

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=0910F038DEBB2C62C41C53A4E30C1C00; Path=/socket
Content-Type: text/html;charset=ISO-8859-1
Content-Length: 582
Date: Fri, 29 Oct 2010 14:45:46 GMT


thank you very much!
AnswerRe: Using WIN32 to Web server to send request,how to remove the HTTP response header Information! Pin
Moak29-Oct-10 6:15
Moak29-Oct-10 6:15 
QuestionMenu Control Pin
AbhiHcl29-Oct-10 3:06
AbhiHcl29-Oct-10 3:06 
AnswerRe: Menu Control Pin
Richard MacCutchan29-Oct-10 3:28
mveRichard MacCutchan29-Oct-10 3:28 
GeneralRe: Menu Control Pin
AbhiHcl29-Oct-10 3:43
AbhiHcl29-Oct-10 3:43 
GeneralRe: Menu Control Pin
Richard MacCutchan29-Oct-10 6:02
mveRichard MacCutchan29-Oct-10 6:02 
GeneralRe: Menu Control Pin
transoft29-Oct-10 12:08
transoft29-Oct-10 12:08 
QuestionMethod CalcFixedLayout in CControlBar Pin
HTT9028-Oct-10 23:47
HTT9028-Oct-10 23:47 
QuestionSecond worker thread should start after first has finished it task. Pin
learningvisualc28-Oct-10 21:25
learningvisualc28-Oct-10 21:25 
AnswerRe: Second worker thread should start after first has finished it task. Pin
KingsGambit28-Oct-10 21:34
KingsGambit28-Oct-10 21:34 
AnswerRe: Second worker thread should start after first has finished it task. Pin
Eytukan28-Oct-10 21:38
Eytukan28-Oct-10 21:38 
AnswerRe: Second worker thread should start after first has finished it task. PinPopular
Cedric Moonen28-Oct-10 21:46
Cedric Moonen28-Oct-10 21:46 
GeneralRe: Second worker thread should start after first has finished it task. Pin
Xie Jinghui28-Oct-10 22:16
Xie Jinghui28-Oct-10 22:16 
AnswerRe: Second worker thread should start after first has finished it task. Pin
Xie Jinghui28-Oct-10 22:11
Xie Jinghui28-Oct-10 22:11 
GeneralRe: Second worker thread should start after first has finished it task. Pin
Sauro Viti28-Oct-10 22:28
professionalSauro Viti28-Oct-10 22:28 
GeneralRe: Second worker thread should start after first has finished it task. Pin
Xie Jinghui28-Oct-10 22:49
Xie Jinghui28-Oct-10 22:49 
AnswerRe: Second worker thread should start after first has finished it task. PinPopular
Aescleal28-Oct-10 23:44
Aescleal28-Oct-10 23:44 
QuestionRadio Button Caption Pin
Benjamin Bruno28-Oct-10 20:01
Benjamin Bruno28-Oct-10 20:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.