如何调试 CgiCC 应用程序
我为 Windows 和 Linux 开发了一个 Win32 C++ cgi 应用程序,并从头开始。 我使用 CgiCC 作为 lib,使用 Visual Studio 2010 作为 IDE。
我该如何调试呢?当我实例化我的 cgicc 类时,我猜程序会保留并等待 CGI 输入。
如何为我的 CGI 输入设置环境?
我设置了一些环境变量,例如 QUERY_STRING。
但我不知道如何提供我的 cgi 应用程序在网络服务器上运行时获得的值。
编辑:
我就快到了。
- 我在浏览时捕获了流量并将该内容写入文件。
- 然后我将标准输入重定向到该文件:“< input.txt”作为 Visual Studio 中的调试命令行参数。< br>
- 我在windows下设置了一些环境变量,如CONTENT_LENGTH和CONTENT_TYPE。
之后,我可以从我的输入中读取一些内容,如下所示:
cgicc::Cgicc cgi;
string u = cgi("user");
但在执行此操作时出现异常(从未分配的内存和类似的异常中读取):
vector<FormFile, allocator<FormFile>> files = cgi.getFiles();
如果正确加载,不知何故不会有任何内容。
I develop a Win32 C++ cgi app for windows and linux and start from scratch.
I use CgiCC as lib and Visual Studio 2010 as IDE.
How can I debug that? When I instanziate my cgicc class the program holds and waits for CGI input I guess.
How can I set up an environment for my CGI input?
I set some environment variables like QUERY_STRING.
But I have no idea how to provide the values my cgi app would get while running on a webserver.
EDIT:
I am almost there.
- I captured the traffic while browsing and wrote that content to a file.
- Then I redirected stdin to that file: "< input.txt" as debug command line arguments in visual studio.
- I set some environment variables under windows like CONTENT_LENGTH and CONTENT_TYPE.
after that I can read some content from my input like this:
cgicc::Cgicc cgi;
string u = cgi("user");
but i get an exception (reading from unallocated memory and exceptions like that) while doing this:
vector<FormFile, allocator<FormFile>> files = cgi.getFiles();
somehow not everthing if loaded correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CGI 应用程序通过环境变量和标准输入接收输入,因此您可以轻松复制 Web 服务器为 CGI 任务设置的环境。
至于环境变量,这里是构成环境变量的列表CGI 协议。我建议您手动设置所有这些,或者更好地通过捕获生产 Web 服务器为工作 cgi 应用程序提供的环境来设置。由于环境变量是由子进程继承的,如果您在 Windows 命令提示符内的环境中设置这些变量,然后从同一窗口调用 Visual Studio IDE,那么当您的 CGI 应用程序在调试器内启动时以及当您的 CGI 应用程序在调试器中启动时,这些变量将可用。您无需调试即可运行它。
在您的情况下,获取标准输入替换可能会更复杂一些,因为您正在使用文件上传表单。 此站点包含一个模板,可以帮助您开始使用 multipart/form-data 格式。通过表单上传文件的官方文档是 RFC 1867。
我希望这有帮助。
CGI apps receive their input via environment variables and standard input, so you can easily replicate the environment that a web server sets up for the CGI task.
As far as environment variables, here is a list of the environment variables that are part of the CGI protocol. I recommend that you set all of them, either by hand or better yet, by capturing the environment given to a working cgi app by a production web server. Since environment variables are inherited by child processes, if you set these up in your environment inside a Windows command prompt and then invoke the Visual Studio IDE from that same window then these variables will be available when your CGI application starts inside the debugger and also when you run it without debugging.
Getting a standard input replacement can be a bit more complex in your case, since you are working with a file upload form. This site contains a template that should get you started with the multipart/form-data format. The official document for file uploads via forms is RFC 1867.
I hope this helps.
我自己解决了这个问题:
然后就成功了!
Solved it by myself:
Then it worked!