c socket ·¢ËÍhttpÇëÇó
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(){
int sockfd;
int len;
struct sockaddr_in address;
int result;
char *strings="GET /svnup/rewrite.php HTTP/1.1\r\nHost: 192.168.1.12\r\nConnection: Close\r\n\r\n";
char ch;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
address.sin_family = AF_INET;
address.sin_addr.s_addr = inet_addr("192.168.1.12");
address.sin_port = htons(80);
len = sizeof(address);
result = connect(sockfd, (struct sockaddr *)&address, len);
if(result == -1){
perror("oops: client1");
return 1;
}
write(sockfd,strings,strlen(strings));
while(read(sockfd,&ch,1))
printf("%c", ch);
close(sockfd);
return 1;
}
HTTP ÇëÇó±¨ÎÄ
l HTTP Command: //·½·¨×ֶΣ¬ËµÃ÷ÆäʹÓõÄÊÇGET ·½·¨
l URI: / //URL ×ֶΣ¬·¢ËÍÇëÇóÖÁ±£´æ¸ÃÍøÕ¾µÄ·þÎñÆ÷¡£
l HTTP Version: //http ÐÒé°æ±¾×ֶΣ¬ÓÃÊǵÄhttp/1.1 °æ±¾
l Accept: //ָʾ¿É±»½ÓÊܵÄÇëÇó»ØÓ¦µÄ½éÖÊÀàÐÍ·¶Î§ÁÐ±í¡£
l Accept-Language: //ÏÞÖÆÁËÇëÇó»ØÓ¦ÖÐÊ×Ñ¡µÄÓïÑÔΪ¼òÌåÖÐÎÄ£¬·ñÔòʹÓÃĬÈÏÖµ¡£
l Accept-Encoding: //ÏÞÖÆÁË»ØÓ¦ÖпɽÓÊܵÄÄÚÈݱàÂëÖµ,ָʾ¸½¼ÓÄÚÈݽâÂ뷽ʽΪgzip,deflate.
l User-Agent: //¶¨ÒåÓû§´úÀí£¬¼´·¢ËÍÇëÇóµÄä¯ÀÀÆ÷ÀàÐÍΪMozilla/4.0
l Host: www.XX.com //\r\n¶¨ÒåÁËÄ¿±êËùÔÚµÄÖ÷»ú
l Connection: Keep-Alive\r\n //¸æËß·þÎñÆ÷ʹÓó־ÃÁ¬½Ó
HTTP »ØÓ¦±¨ÎÄ
l HTTP Version: HTTP/1.1 //·þÎñÆ÷ÓõÄÊÇHTTP/1.1 °æ±¾
l HTTP Status: 200 //ÇëÇó³É¹¦£¬ÐÅÏ¢¿ÉÒÔ¶ÁÈ¡£¬°üº¬ÔÚÏìÓ¦µÄ±¨ÎÄÖÐ
l Date: //Ö¸·þÎñÆ÷´ÓÎļþϵͳÖмìË÷µ½¸Ã¶ÔÏ󣬲åÈëµ½ÏìÓ¦±¨ÎÄ£¬²¢·¢Ë͸ÃÏìÓ¦±¨ÎĵÄʱ¼ä
l Server: //±íÃ÷¿Ì±¨ÎÄÊÇÓÉÒ»¸öApache/2.0.52 µÄ·þÎñÆ÷²úÉúµÄ
l X-Powered-By: //±íÃ÷ÊÇʹÓÃPHP£¨°æ±¾£©µÄ¶¯Ì¬ÍøÒ³
l Set- cookie: //
l Vary: //
l Content-Length: //±íÃ÷ʵÌåµÄ³¤¶È
l Connection: //¸æËß¿Í»§»úÔÚ±¨ÎÄ·¢ËÍÍê±ÏºóÈÔÈ»±£³ÖÁ¬½Ó
l Content-Type: //±íÃ÷ʵÌåÖеĶÔÏóÊÇhtml Îĵµ
l Binary Data: //¶þ½øÖÆÊý¾Ý
˵Ã÷£ºÔÚ·þÎñÆ÷¸øµÄ»ØÓ¦ÇëÇóÖУ¬ÎÒÃÇ¿ÉÒÔ´Ó״̬ÂëÖп´µ½·ÃÎʵÄÏà¹ØÐÅÏ¢¡£×´Ì¬Âë±íʾÏìÓ¦ÀàÐ
Ïà¹ØÎĵµ£º
CÓïÑԺ궨ÒåʵÓÃ×ܽá
ºê¶¨ÒåÁËÒ»¸ö´ú±íÌض¨ÄÚÈݵıêʶ·û¡£
Ô¤´¦Àí¹ý³Ì»á°ÑÔ´´úÂëÖгöÏֵĺê±êʶ·ûÌæ»»³Éºê¶¨ÒåʱµÄÖµ¡£
ºê×î³£¼ûµÄÓ÷¨ÊǶ¨Òå´ú±íij¸öÖµµÄÈ«¾Ö·ûºÅ¡£
ºêµÄµÚ¶þÖÖÓ÷¨ÊǶ¨Òå´ø²ÎÊýµÄºê£¬ÕâÑùµÄºê¿ÉÒÔÏóº¯ÊýÒ»Ñù±»µ÷Ó㬵«ËüÊÇÔÚµ÷ÓÃÓï¾ä´¦Õ¹¿ªºê£¬²¢Óõ÷ÓÃʱµÄʵ¼Ê²ÎÊýÀ ......
//ÒÔϳÌÐòÊÇʵÏÖСдת´óд³ÌÐò
#include<stdio.h>
void to_upper(char *str)
{
for(;*str !='\0';str++)
{
if(unsigned(*str-'a')<='z'-'a')
*str-='a'-'A';//Ð ......
ͻ񻣼
Îĵµ×«Ð´ÊÇÒ»ÏîÊ®·Ö·±Ëö¶øÇÒ·ÑÁ¦µÄ¹¤×÷£¬ÏàÐÅÒѾÓкܶàÈ˶ԴËÉî¸ÐÍ·Í´¡£ÎĵµÉú³É¹¤¾ßµÄ³öÏÖ×î´óÏ޶ȵذïÖú³ÌÐòÔ±½â¾öÁËÕâ¸öÎÊÌ⣬ÕâЩ¹¤¾ßͨ³£¿ÉÒÔ´Ó³ÌÐòÔ´´úÂë×Ô¶¯Éú³ÉÎĵµ£¬´ó´ó·½±ãÁËÎĵµ¹¤×÷¡£ÕâƪС¶«Î÷Ö÷Òª½éÉÜÁËÈçºÎÓÃVIMºÍdoxygenÀ´¿ìËÙÉú³É×¢ÊÍ£¬²¢ÓÃ×îÉٵĶîÍâÀͶ¯À´Íê³Éרҵˮ׼µÄ³ÌÐòÎĵµµÄ¹ý³Ì¡£½ö¹© ......
Ç°¼¸Ìì²Î¼Óij¹«Ë¾µÄ±ÊÊÔ£¬ÓÐÒ»µÀÌâÊÇÓô¿CʵÏÖÒ»¸ö·ºÐͺ¯Êý¡£ÓôÃÆÁ˺þÃÓÃC++Ä£°åʵÏÖÁË¡£
ºêÓÐÈçϵÄÌص㣺
1.ÓëconstÏà±È£¬ºêÊÇÔÚÔ¤±àÒëµÄʱºòÍê³ÉµÄ
2.define Ö»×ö¼òµ¥µÄÌæ»»£¬²»×öÀàÐÍ°²È«¼ì²é
3.ʹÓò»µ±»áÒýÆðºÜ¶àÎÊÌâ
ºêµÄÓ÷¨£º
1.¼òµ¥µÄºê¶¨Òå
#define MAX 1024
2.ºê¶¨Ò幦ÄÜ¿é
#define MAX(a,b) ( ......