cgi

In a Python3 CGI script, how can I read the raw form data in a POST?

我只是一个虾纸丫 提交于 2020-01-03 16:58:29
问题 Yes, I'm aware of cgi.FieldStorage , but, being some form of unordered dictionary, it does not preserve the order of the original data (see below for proof). Since I wish to use this data with PayPal IPN, order is important PayPal docs here, which say "...you must send back the contents in the exact order they were received..." Alternatively, os.environ.get('QUERY_STRING') looks perfect, however, it seems to only work for a GET . Example code: (myscript.py) #!/usr/bin/python3 import cgi, os

Possible to upload file and parse the json result?

跟風遠走 提交于 2020-01-03 03:40:09
问题 I have a form that is used to upload the file and a CGI program in the server side to process the uploaded file. The file will be renamed to a different file name that I want to pass back to the client, I want to use JSON to return the result, but the browser always prompts me to save the returnd document to a file... Conclusion: I want to upload a file and from the HTTP response I want to parse it to get the new filename generated by server side. <form action="/a.bc?cmd=upload&user_name

关于CGI和FastCGI的理解

◇◆丶佛笑我妖孽 提交于 2020-01-02 16:27:56
关于CGI和FastCGI的理解 CGI的引入 在网站的整体架构中,Web Server(如nginx,apache)只是内容的分发者,对客户端的请求进行应答。 如果客户端请求的是index.html这类静态页面,那么Web Server就去文件系统中找对应的文件,找到返回给客户端(一般是浏览器),在这里Web Server分发的就是是静态数据。 事物总是不 断发展,网站也越来越复杂,所以出现动态技术。但是服务器并不能直接运行 php,asp这样的文件,自己不能做,外包给别人吧,但是要与第三做个约定,我给你什么,然后你给我什么,就是握把请求参数发送给你,然后我接收你的处 理结果给客户端。那这个约定就是 common gateway interface,简称cgi。这个协议可以用vb,c,php,python 来实现。cgi只是接口协议,根本不是什么语言。下面图可以看到流程: 在这个过程中,Web Server并不能直接处理静态或者动态请求,对于静态请求是直接查找然后返回数据或者报错信息,对于动态数据也是交付给其他的工具(这里的PHP解析器)进行处理。 那么Web Server和处理工具(这里的php-fpm)是怎样进行交互的呢?传输的是那些数据呢?这些数据的格式又是怎样的呢? 由此便引出了今天的主角:CGI 1.关于CGI 1.1.什么是CGI? 1) CGI(Common

Interrupted server-side perl CGI script when client-side browser closes

二次信任 提交于 2020-01-02 07:35:14
问题 I've been trying to solve a little problem for quite a while now but it seems I'm not able to. I wrote an HTML page which calls a perl CGI script upon submitting a form. This CGI executes a certain number of tasks server-side and I made the script print the steps of these tasks into an iframe on the HTML page. The thing is, if the client closes his browser or just goes out of the page, the CGI script is interrupted on server-side. HTML code: <form action="/path/to/script.cgi" method="post"

How to locate Perl modules in the same directory as the script

夙愿已清 提交于 2020-01-02 07:23:26
问题 Now that recent versions of Perl have removed "." from @INC, I'm curious about best practices for module file location. Until now, the *.pm files associated with each application on our web site were in the same directory as the scripts. This, I gather, creates a security vulnerability. We don't have write access to the remaining directories in @INC. We could just leave the pm files where they are, and add use lib "."; to all our existing scripts, but wouldn't this just preserve the security

Parse multipart/form-data using cgi.FieldStorage; None keys

霸气de小男生 提交于 2020-01-01 09:22:51
问题 The following piece of code should be able to run in Python 2.7 and Python 3.x. from __future__ import unicode_literals from __future__ import print_function import cgi try: from StringIO import StringIO as IO except ImportError: from io import BytesIO as IO body = """ --spam Content-Disposition: form-data; name="param1"; filename=blob Content-Type: binary/octet-stream value1 --spam-- """ parsed = cgi.FieldStorage( IO(body.encode('utf-8')), headers={'content-type': 'multipart/form-data;

Internet Explorer 8 + Deflate

冷暖自知 提交于 2020-01-01 05:30:13
问题 I have a very weird problem.. I really do hope someone has an answer because I wouldn't know where else to ask. I am writing a cgi application in C++ which is executed by Apache and outputs HTML code. I am compressing the HTML output myself - from within my C++ application - since my web host doesn't support mod_deflate for some reason. I tested this with Firefox 2, Firefox 3, Opera 9, Opera 10, Google Chrome, Safari, IE6, IE7, IE8, even wget.. It works with ANYTHING except IE8. IE8 just says

Pros and Cons of different approaches to web programming in Python

痞子三分冷 提交于 2019-12-31 09:15:14
问题 I'd like to do some server-side scripting using Python. But I'm kind of lost with the number of ways to do that. It starts with the do-it-yourself CGI approach and it seems to end with some pretty robust frameworks that would basically do all the job themselves. And a huge lot of stuff in between, like web.py, Pyroxide and Django. What are the pros and cons of the frameworks or approaches that you've worked on ? What trade-offs are there? For what kind of projects they do well and for what

What is wrong with my sscanf format

六眼飞鱼酱① 提交于 2019-12-31 05:07:11
问题 I'm trying to deal with form data in c here. fgets(somedata, bufferone, stdin); if I printf 'somedata', I get: username=John&password=hispass123 now when I try to sscanf using char usr[100], pass[100]; sscanf(somedata, "username=%s&password=%s", usr, pass); printf("Content-type: text/html\n\n"); printf("%s is value 1\n", usr); printf("%s is value 2\n", pass); than I get John&password=hispass123 is value 1 ?? is value 2 I suspect, the first call reads up to the null-terminator, and then second

centos7下部署nginx与php

北城以北 提交于 2019-12-31 01:02:44
背景介绍 相信读者在看这篇文章之前已经fastcgi,php-fpm有所了解。大概来讲php语言需要fastcgi程序,即php解释器解释,而php解释器需要php-fpm管理器进行调度。 以下对CGI、FastCGI、php-fpm之间关系进行通俗解释(来源于知乎用户Journey Lin): 讲Fastcgi之前需要先讲CGI,CGI是为了保证web server传递过来的数据是标准格式的,它是一个协议,方便CGI程序的编写者。Fastcgi是CGI的更高级的一种方式,是用来提高CGI程序性能的。web server(如nginx)只是内容的分发者。比如,如果请求/index.html,那么web server会去文件系统中找到这个文件,发送给浏览器,这里分发的是静态资源。如果现在请求的是/index.php,根据配置文件,nginx知道这个不是静态文件,需要去找PHP解析器来处理,那么他会把这个请求简单处理后交给PHP解析器。此时CGI便是规定了要传什么数据/以什么格式传输给php解析器的协议。当web server收到/index.php这个请求后,会启动对应的CGI程序,这个程序就是PHP的解析器。接下来PHP解析器会解析php.ini文件,初始化执行环境,然后处理请求,再以CGI规定的格式返回处理后的结果,退出进程。web server再把结果返回给浏览器