且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CGI应用程序中某些页面上的HTTP 502错误

更新时间:2022-10-29 17:05:33

请参阅


Hello all

I have been working with an existing CGI application under linux with C++. The problem that on some pages it gives me the error

502 Bad Gateway
The CGI was not CGI 1.1 compliant

Before that it wrote on the same page "cgi_header: unable to find LFLF"!

What's more weird is the program starts correctly but when I go to specific pages I get this error. I tried to use an fstream object to log where the exact point of the crash but I found out that if I only write this

ofstream ff("test.txt", ofstream::app);

// The Code
// That displays
// The page

// Last line
ff.close();



and even not writing anything to the stream just declare and close it will make the page run correctly!

The system uses the same code but with different parameters on some pages, the page's contents come form sqlite 3 database and the database data is correct and can be viewed , there are other pages that works perfectly on the same code but there are specific pages that stuck on this error :\ (in other words, same code on other pages work!)

I've checked everything regarding the code, database or HTML. I also searched online and all results tells the same thing, I should make sure to print an empty line after "Content-type:text/HTML" (cout << "Content-type:text/HTML\n\n";) and even this is correct in my code.

PS: This situation happens when I run the application via an embedded linux device I'm using, If I run it through the localhost on my PC everything works.

Any help is appreciated, Thanks!

Refer to this