i am sorry for my list.
i have not given enough information for my question.
my os is fedora use gcc compile
i am trying to write a application to login google picasa, now i
will give more code for it
thanks for your attention
if (connect(sockfd, (struct sockaddr *) (&server_addr),
sizeof(struct sockaddr)) == -1) { /*Á¬½ÓÍøÕ¾ */
if (DEBUG)
fprintf(stderr, "Connect Error:%s\a\n", strerror(errno));
exit(1);
}
/* SSL³õʼ»¯ */
SSL_library_init();
SSL_load_error_strings();
ctx = SSL_CTX_new(SSLv23_client_method());
if (ctx == NULL) {
ERR_print_errors_fp(stderr);
exit(1);
}
ssl = SSL_new(ctx);
if (ssl == NULL) {
ERR_print_errors_fp(stderr);
exit(1);
}
/* °ÑsocketºÍSSL¹ØÁª */
ret = SSL_set_fd(ssl, sockfd);
if (ret == 0) {
ERR_print_errors_fp(stderr);
exit(1);
}
RAND_poll();
while (RAND_status() == 0) {
unsigned short rand_ret = rand() % 65536;
RAND_seed(&rand_ret, sizeof(rand_ret));
}
ret = SSL_connect(ssl);
if (ret != 1) {
ERR_print_errors_fp(stderr);
exit(1);
}
sprintf(request, "POST /accounts/ClientLogin HTTP/1.0\r\nContent-
length:1344\r\nContent-type: application/x-www-form-urlencoded\r
\naccountType=HOSTED_OR_GOOGLE&
[email protected]&Passwd=031126&service=lh2&source=sd4-
aa-1.0\r\nHost: %s:%d\r\nConnection: Close\r\n\r\n",
host_addr,portnumber);
if (DEBUG)
printf("%s", request); /* prepare request£¬ */
if (host_file && *host_file)
pt = Rstrchr(host_file, '/');
else
pt = 0;
memset(local_file, 0, sizeof(local_file));
if (pt && *pt) {
if ((pt + 1) && *(pt + 1))
strcpy(local_file, pt + 1);
else
memcpy(local_file, host_file, strlen(host_file) - 1);
} else if (host_file && *host_file)
strcpy(local_file, host_file);
else
strcpy(local_file, "index.html");
if (DEBUG)
printf("local filename to write:%s\r\n", local_file);
/send https request */
send = 0;
totalsend = 0;
nbytes = strlen(request);
while (totalsend < nbytes) {
send = SSL_write(ssl, request + totalsend, nbytes -
totalsend);
if (send == -1) {
if (DEBUG)
ERR_print_errors_fp(stderr);
exit(0);
}
totalsend += send;
if (DEBUG)
printf("%d bytes send OK!\n", totalsend);
}
fp = fopen(local_file, "a");
if (!fp) {
if (DEBUG)
printf("create file error! %s\n", strerror(errno));
return 0;
}
if (DEBUG)
printf("\nThe following is the response header:\n");
i = 0;
/* connected£¬response https */
while ((nbytes = SSL_read(ssl, buffer, 1)) == 1) {
if (i < 4) {
if (buffer[0] == '\r' || buffer[0] == '\n')
i++;
else
i = 0;
if (DEBUG)
printf("%c", buffer[0]); /*print https header
info */
} else {
fwrite(buffer, 1, 1, fp);
i++;
if (i % 1024 == 0)
fflush(fp);
}
}
fclose(fp);