Bonjour a toutes et a tous !
voila j'ai du code qui télécharge l'image qui se trouve en haut de votre écran de cppfrance a gauche de fiche mais j'arrive qu'a récupèrer 7 octet voila mon code :
#include <winsock2.h>
#include <stdio.h>
#pragma comment(lib,"ws2_32.lib")
#define BUFSIZE 1024
#define HTTP_GET "GET "
#define HTTP_PROTO " HTTP/1.1\r\nAccept: */*\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)\r\nHost: " /*ok*/
void main(){
WSADATA WSAData;
WSAStartup(MAKEWORD(2,0), &WSAData);
SOCKADDR_IN sin;
SOCKET sock;
char body [90000];
char header[1000];
char tmp [1000];
char path[100];
char host[100];
char file[90000];
int error;
char * p;
int i,j,k;
strcpy(path,"/g/usr.gif");
strcpy(host,"cppfrance.com\r\n\r\n");
sock = socket(AF_INET, SOCK_STREAM, 0);
sin.sin_addr.s_addr = inet_addr("213.161.194.215");
sin.sin_family = AF_INET;
sin.sin_port = htons(80);
error = -1;
printf("connexion\n");
error = connect(sock, (SOCKADDR *)&sin, sizeof(sin));
if (error < 0)
printf("erreur de connexion");
strcpy(tmp,HTTP_GET);
strcat(tmp,path);
strcat(tmp,HTTP_PROTO);
strcat(tmp,host);
strcat(tmp,"\r\n\r\n");
printf("%s",tmp);
printf("envoi de la requete\n");
send(sock, tmp, strlen(tmp), 0);
printf("reception des données\n");
recv(sock, header,sizeof(header), 0);
printf("header : %s\n /header",header);
i=0;
while(i<strlen(header))
{
char *buf = (char*)malloc(256);
for(j=0;header[i+j]!='\r'||header[i+j+1]!='\n';j++)
buf[j] = header[i+j];
buf[j]='\0';
printf("%s\n",buf);
i+=j+2;
if(strlen(buf)==0)
break;
}
printf(" I = %d\n",i);
k=strlen(header)-i;
printf(" K = %d\n",k);
for (j=0;j<=k;j++)
body[j]=header[i+j];
printf("Body %s \n /body",body);
FILE* F;
F=fopen("dasih.gif","wb");
fwrite(body,strlen(body),1,F);
fclose(F);
system("pause");
}
Je vois pas ou j'ai un problème!
Sébastien Metthez
www.sebastien-metthez.com
le problème vient souvent de l'interface chaise cl