Danh mục

HHTP CLIENT EXAMPLE

Số trang: 1      Loại file: pdf      Dung lượng: 6.83 KB      Lượt xem: 11      Lượt tải: 0    
Jamona

Xem trước 1 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

HHTP CLIENT EXAMPLE*HTTP RFC SP: space (khoang trang) CRLF: \r\n REQUEST SYNTAX: Request = Request-Line *( general-header | request-header | entity-header ) CRLF [ message-body ]
Nội dung trích xuất từ tài liệu:
HHTP CLIENT EXAMPLE /* strcat(buffer,HOST:HHTP CLIENT EXAMPLE );strcat(buffer,host);strcat(buffer,\r\n);*HTTP RFC strcat(buffer,CONNECTION: CLOSE\r\n\r\n);SP: space (khoang trang) }CRLF: \r\nREQUEST SYNTAX: u_long LookupAddress(const char* pcHost); void error(char * msg); Request = Request-Line *( general-header int main(int argc, char* argv[]) | request-header { | entity-header ) WSADATA wsaData; CRLF WSAStartup(MAKEWORD(1,1),&wsaData); [ message-body ] /////////////////////////// printf(Client...); SOCKET wsk=socket(AF_INET,SOCK_STREAM,0); Request-Line = Method SP Request-URI SPHTTP-Version CRLF struct hostent *hostname=gethostbyname(SERVER_ADDR); Method = OPTIONS ///////////////////////////// | GET struct sockaddr_in server_addr; | HEAD | POST server_addr.sin_family = AF_INET; | PUT server_addr.sin_addr.S_un.S_addr=LookupAddre | DELETE ss(SERVER_ADDR); | TRACE server_addr.sin_port = htons(MY_PORT); | extension-method if (connect(wsk,(struct sockaddr*)&server_addr,sizeof(server_addr)) < 0) Request-URI = * | absoluteURI | error(ERROR connecting);abs_path printf(connected!\n); //Send REQUEST Ex : absoluteURI: char buffer[1024];int n;http://www.w3.org/pub/WWW/TheProject.html makeRequestStr(buffer,URL,SERVER_ADDR); abs_path: send(wsk,buffer,strlen(buffer),0);/pub/WWW/TheProject.html //GET RESPONSE printf(Http content: ); HTTP-Version = HTTP/1.1 n = recv(wsk,buffer,1024,0); | HTTP/1.0 buffer[n]=\0; printf(%s\n,buffer); EX: closesocket(wsk); GET ///////////////////////////http://www.w3.org/pub/WWW/TheProject.html HTTP/1.1 WSACleanup(); Host: www.w3.org return 0; or: } GET /pub/WWW/TheProject.html HTTP/1.1 void error(char * msg) */ { printf(%s\n,msg);#include exit(0);#include }//////#define MY_PORT 80#define SERVER_ADDR www3.tuoitre.com.vn u_long LookupAddress(const char* pcHost)#define URL {http://www3.tuoitre.com.vn/transweb/tygia.htm u_long nRemoteAddr = inet_addr(pcHost); if (nRemoteAddr == INADDR_NONE) {void makeRequestStr(char * buffer,const char * // pcHost isnt a dotted IP, so resolve iturl, const char * host) through DNS{ hostent* pHE = gethostbyname(pcHost); /* if (pHE == 0) { Example: return INADDR_NONE; s = GET }http://www3.tuoitre.com.vn/transweb/tygia.htm nRemoteAddr = *((u_long*)pHE-HTTP/1.1\r\n; >h_addr_list[0]); s += Host: www3.tuoitre.com.vn\r\n; } s += Connection: Close\r\n\r\n; */ return nRemoteAddr; strcpy(buffer,GET );strcat(buffer,url); } strcat(buffer, HTTP/1.1\r\n);

Tài liệu được xem nhiều: