Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
B.Eckel - Thinking in C++, Vol.2, 2nd edition.pdf
Скачиваний:
52
Добавлен:
08.05.2013
Размер:
2.09 Mб
Скачать

which runs on virtually all platforms. Some word-processing/spreadsheet packages even come with Web servers. It’s also quite cheap and easy to get an old PC and install Linux along with an inexpensive network card. Linux automatically sets up the Apache server for you, and you can test everything on your local network as if it were live on the Internet. One way or another it’s possible to install a Web server for local tests, so you don’t need to have a remote Web server and permission to install CGI programs on that server.

One of the advantages of this design is that, now that CGIpair and CGImap are defined, most of the work is done for you so you can easily create your own CGI program simply by modifying main( ).

Using POST

The CGIpair and CGImap from CGImap.h can be used as is for a CGI program that handles POSTs. The only thing you need to do is get the data from a Post object instead of from the QUERY_STRING environment variable. The following listing shows how simple it is to write such a CGI program:

//: C10:CGI_POST.cpp

//CGImap works as easily with POST as it

//does with GET.

#include "CGImap.h" #include <iostream> using namespace std;

int main() {

cout << "Content-type: text/plain\n" << endl; Post p; // Get the query string

CGImap query(p);

// Test: dump all names and values for(CGImap::iterator it = query.begin();

it != query.end(); it++) { cout << (*it).first << " = "

<< (*it).second << endl;

}

} ///:~

After creating a Post object, the query string is no different from a GET query string, so it is handed to the constructor for CGImap. The different fields in the vector are then available just as in the previous example. If you wanted to get even more terse, you could even define the Post as a temporary directly inside the constructor for the CGImap object:

CGImap query(Post());

To test this program, you can use the following Web page:

Appendix B: Programming Guidelines

548

Соседние файлы в предмете Численные методы
  • #
    08.05.20133.99 Mб22A.Menezes, P.van Oorschot,S.Vanstone - HANDBOOK OF APPLIED CRYPTOGRAPHY.djvu
  • #
  • #
    08.05.20135.91 Mб25B.Eckel - Thinking in Java, 3rd edition (beta).pdf
  • #
  • #
    08.05.20136.09 Mб17D.MacKay - Information Theory, Inference, and Learning Algorithms.djvu
  • #
    08.05.20133.85 Mб15DIGITAL Visual Fortran ver.5.0 - Programmers Guide to Fortran.djvu
  • #
    08.05.20131.84 Mб12E.A.Lee, P.Varaiya - Structure and Interpretation of Signals and Systems.djvu