Upgrade tinyhttpd-0.1.0 to support Web page display images

Source: Internet
Author: User
Tags html header

TINYHTTPD is a very good tool to learn the HTTP protocol, but because it is too simple to display pictures on the Web page, so I changed some code, so that TINYHTTPD can be realistic images for beginners to learn and familiar with the HTTP protocol, ubuntu14.04 under direct make can, has been tested pass.

Code: download.csdn.net/detail/qiankun1993/9524289

The main increase is two functions, the first is the function of the image wrapper header, when transferring the picture, the Content-type in the HTML header is set to Image/png:

void Headers2 (int client,Constchar *FileName) {Char buf[1024]; (void) filename;/*Could use filename to determine file type*/strcpy (BUF, "http/1.0 ok\r\n); Send (client, buf, strlen (BUF), 00 "content-type:image/png\r\n" ); Send (client, buf, strlen (BUF), 0 "\r\n" ); Send (client, buf, strlen (BUF), 0    

The second is a function to read the local picture file, using the following CAT2 () to read the image file's data:

void Cat2 (int client, FILE *resource) {char buf[1024char C; while ((fscanf (Resource, " %ceof) { Send (client, &c, 1, 0 ); printf ( "%c" ,C); } printf ( "%c" ,C)}                 

Then you can display the image on the Web page, this is only for beginners to learn, Daniel do not despise me.

Upgrade tinyhttpd-0.1.0 to support Web page display images

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.