Webserver missing header of HTTP answer in .cgi files

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Webserver missing header of HTTP answer in .cgi files

Jump to solution
921 Views
kappa74
Contributor IV

Good mornig,

I'm using MCF52255 with MQX3.8.1 developped by CW10.2. I implemented a webserver but when I try to enter in the my website, inserting a password, I will get an error on Mozilla which indicates that there isn't the header of the HTTP answer message. I passed a file called "password.cgi" which has not the header message of HTTP (the content-type is missing).

Is it possible that the libraries don't put header HTTP message if I transfer a .cgi file? To put the header of HTTP message, do I have to transfer an html file?

How can I put a dinamyc part of the HTML page using cgi and sending the header of the HTTP message?

I attached the error which I get on Mozilla browser.

I attached the file html of my home page.

 

Best Regards

Fortunato Mirko


Original Attachment has been moved to: home.html.zip

Labels (1)
1 Solution
371 Views
Martin_
NXP Employee
NXP Employee

Actually, I think it's not the library but the application code should trigger the header of HTTP message.

For a cgi web page, application callback functions are defined in HTTPD_CGI_LINK_STRUCT.

From the cgi callback function, we can request the RTCS to send a header. An example for this in MQX 4.0, in /rtcs/examples/httpsrv/cgi.c, cgi callback functions should look like this:

static _mqx_int cgi_rtc_data(HTTPD_SESSION_STRUCT *session)

{

  TIME_STRUCT time;

  int min, hour;

  

  _time_get(&time);

  

  min = time.SECONDS / 60;

  hour = min / 60;

  min %= 60;

  

  session->response.contenttype = CONTENT_TYPE_PLAIN;

  httpd_sendhdr(session, 0, 0);

  

  CGI_SEND_NUM(hour);

  CGI_SEND_NUM(min);

  CGI_SEND_NUM(time.SECONDS % 60);

  return session->request.content_len;

}

Notice the write to response struct contenttype and a call to httpd_sendhdr().

View solution in original post

1 Reply
372 Views
Martin_
NXP Employee
NXP Employee

Actually, I think it's not the library but the application code should trigger the header of HTTP message.

For a cgi web page, application callback functions are defined in HTTPD_CGI_LINK_STRUCT.

From the cgi callback function, we can request the RTCS to send a header. An example for this in MQX 4.0, in /rtcs/examples/httpsrv/cgi.c, cgi callback functions should look like this:

static _mqx_int cgi_rtc_data(HTTPD_SESSION_STRUCT *session)

{

  TIME_STRUCT time;

  int min, hour;

  

  _time_get(&time);

  

  min = time.SECONDS / 60;

  hour = min / 60;

  min %= 60;

  

  session->response.contenttype = CONTENT_TYPE_PLAIN;

  httpd_sendhdr(session, 0, 0);

  

  CGI_SEND_NUM(hour);

  CGI_SEND_NUM(min);

  CGI_SEND_NUM(time.SECONDS % 60);

  return session->request.content_len;

}

Notice the write to response struct contenttype and a call to httpd_sendhdr().