C# CR must be followed by LF -


i write simple http server myself, , use c# windows form retrieve content of http server. c# program said protocol violation, cr must followed lf. know issue can solved adding configuration files c# projects. want know reason. http server code in below.

/*  * handle connection each client  * */ void *httpconnection_handler(void *socket_desc) {     //get socket descriptor     int sock = *(int*)socket_desc;     int read_size;     char *message = "http/1.1 200 ok\r\ncontent-type: text/xml; \r\ncharset=utf-8\r\n\r\n";     char *end = "\r\n";     char send_message[3000] = {0};      //send messages client     char * buffer = 0;     long length;     file * f = fopen ("/mnt/internal_sd/device-desc.xml", "r");     if (f)     {       fseek (f, 0, seek_end);       length = ftell (f);       fseek (f, 0, seek_set);       buffer = malloc (length);       if (buffer)       {         fread (buffer, 1, length, f);       }       fclose (f);     }      strcat(send_message, message);     strcat(send_message, buffer);     strcat(send_message, end);       write(sock , send_message , length + strlen(message));     sleep(1);     shutdown(sock, shut_wr);     //free socket pointer     close(sock);      return 0; } 

my c# code in below.

using (webclient webclient = new webclient()) {     webclient.encoding = encoding.utf8;     contents = webclient.downloadstring(url); } 

the exception message is

requestfailed: server committed protocol violation. section=responseheader detail=cr must followed lf

it may because of \r\n have inside of content-type header. charset should part of content-type header line.

char *message = "http/1.1 200 ok\r\ncontent-type: text/xml;charset=utf-8\r\n\r\n"; 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -