标签: httpserver

Python CGIHTTPServer 默认目录

我有以下用于 CGI 处理 HTTP 服务器的最小代码,这些代码源自内管上的几个示例:

#!/usr/bin/env python

import BaseHTTPServer
import CGIHTTPServer
import cgitb;

cgitb.enable()  # Error reporting

server = BaseHTTPServer.HTTPServer
handler = CGIHTTPServer.CGIHTTPRequestHandler
server_address = ("", 8000)
handler.cgi_directories = [""]

httpd = server(server_address, handler)
httpd.serve_forever()
Run Code Online (Sandbox Code Playgroud)

然而,当我执行脚本并尝试使用 CGI 在同一目录中运行测试脚本时http://localhost:8000/test.py,我看到的是脚本的文本,而不是执行的结果。

权限都设置正确,测试脚本本身不是问题(因为python -m CGIHTTPServer当脚本驻留在 cgi-bin 中时,我可以使用 运行它)。我怀疑这个问题与默认的 CGI 目录有关。

我怎样才能让脚本执行?

python cgi httpserver cgihttprequesthandler cgihttpserver

6
推荐指数
1
解决办法
7284
查看次数

OkHttp:<-- HTTP 失败:java.net.UnknownServiceException:网络安全策略不允许与 10.0.2.2 的 CLEARTEXT 通信

我已经成功地在我的 Android 应用程序中使用 Firebase 身份验证实现了谷歌登录在此处输入图片说明

如您所见,我已使用我的帐户登录并显示在 Firebase 控制台上。

使用 Google Sign-in 登录后,函数firebaseAuthWithGoogle使用 Firebase 对用户进行身份验证:

private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mFirebaseAuth.signInWithCredential(credential)
        .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if (task.isSuccessful()) {
                    // Sign in success, update UI with the signed-in user's information
                    Log.d(TAG, "signInWithCredential:success");
                    final FirebaseUser user = mFirebaseAuth.getCurrentUser();


                    //This is to connect to the http server and save the user data …
Run Code Online (Sandbox Code Playgroud)

httpserver android-studio retrofit okhttp android-security

6
推荐指数
2
解决办法
5930
查看次数

node.js使HTTP服务器的请求和响应全局化?

我刚开始使用node.js,并通过http://nodebeginner.org/index.html进行了运行。很好的入门教程,但我真的很想知道是否可以使请求和响应都成为“全局”,以便为当前传入请求加载的任何模块都可以访问这些...而不是注入。

有想法吗?

javascript httpserver node.js

5
推荐指数
1
解决办法
2108
查看次数

在ubuntu上安装并运行browserquest

我已经安装了node.js和必要的包来运行browserquest.我已经启动了在端口8080上运行的browserquest服务器,当我进入浏览器并键入http:// localhost:8080/status时,我可以看到服务器正在运行,并且当前没有连接客户端.我在client/config/build_config.json文件中使用这样的配置构建客户端

{
   "host": "http://127.0.0.1",
   "port": 8080
}
Run Code Online (Sandbox Code Playgroud)

我在bin/build.sh中构建我的客户端.然后我运行此命令来创建http-server来提供客户端文件.

http-server path-to-client-build -p 8000
Run Code Online (Sandbox Code Playgroud)

我可以通过转到http:// localhost:8000/index.html来查看运行httpserver的索引页面,但是当我尝试连接时,在连接到服务器后它会卡住.

注意:我使用此http服务器来托管客户端文件http://search.npmjs.org/#/http-server

javascript httpserver node.js

5
推荐指数
1
解决办法
6263
查看次数

如何使用read,readpartial和read_nonblock从ruby中的TCPServer套接字读取

我有两个关于从套接字读取的问题,以及如何在像Unicorn或Mongrel这样的Ruby服务器上进行管理

  1. 我已经知道从套接字读取不同于读取文件,并且没有发送明显的EOF消息,并且数据是无穷无尽的.那么你怎么知道何时停止阅读?我的TCPServer例如在这种情况下,当我通过http://localhost:9799浏览器访问我的服务器时,它在没有更多数据要读取之后挂起,它也不会抛出EOFError.

require 'socket'

READ_CHUNK = 1024
socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM)
addr = Socket.pack_sockaddr_in(9799, '127.0.0.1')
socket.bind(addr)
socket.listen(Socket::SOMAXCONN)
socket.setsockopt(:SOCKET, :REUSEADDR, true)

puts "Server is listening on port = 9799"
loop do 
    connection, addr_info = socket.accept
    data_buffer = ""

    loop do
        begin
            connection.read_nonblock(READ_CHUNK, data_buffer)
            puts "Buffer = #{data_buffer}"
        rescue Errno::EAGAIN => e
            IO.select([connection])         
            retry
        rescue EOFError
            break
        end
    end
    connection.write("HTTP/1.1 200 \r\n")
    connection.write("Content-Type: text/html\r\n")
    connection.write("Status 200 \r\n")
    connection.write("Connection: close \r\n")
    connection.write("Hello World \r\n")
    connection.close
end

我想知道Ruby服务器使用的最佳实践/标准方法.我看到Unicorn使用来自kgio库的read_nonblock而mongrel使用了readpartial(我不确定这些但是通过代码这就是我认为采用的方法.)即使检查\ …

ruby unix nonblocking httpserver tcpserver

5
推荐指数
1
解决办法
5193
查看次数

Python HTTP服务器在POST请求时没有响应

我想使用python创建一个HTTP服务器来托管我的网站.我已经实现了do_GET()方法并且它工作正常,但是当我尝试POST方法时,服务器在我重新加载页面之前没有响应.然后它醒来,tring完成POST,但意识到连接已经结束.之后,它提供GET方法(因为我重新加载页面)并继续正常运行.

我在客户端使用jQuery,但我也试过html表单.即使我在另一个浏览器中打开页面也没有变化,因此它必须是服务器端的例外.

这是客户端javascript:

function Send()
        {
            jQuery.post("address", "Blah!", function (data) {
                //get response
                alert(data);
            });
        }
Run Code Online (Sandbox Code Playgroud)

这是服务器代码(我使用的是python 3.3.4):

class MyHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
    def do_POST(self):
        print("Data: " + str(self.rfile.read(), "utf-8")) #show request

        response = bytes("This is the response.", "utf-8") #create response

        self.send_response(200) #create header
        self.send_header("Content-Length", str(len(response)))
        self.end_headers()

        self.wfile.write(response) #send response
Run Code Online (Sandbox Code Playgroud)

这是来自服务器的日志:

10.175.72.200 - - [01/Apr/2014 19:11:26] "GET / HTTP/1.1" 200 -
Data: Blah!
10.175.72.200 - - [01/Apr/2014 19:11:47] "POST /address HTTP/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('10.175.72.200', 2237) …
Run Code Online (Sandbox Code Playgroud)

python post httpserver

5
推荐指数
1
解决办法
4662
查看次数

如何在python 2.7.6中导入_ssl?

我的http服务器基于BaseHTTPServer和Python 2.7.6.现在我希望它支持ssl传输,所谓的https.

我已经安装了pyOpenSSL并使用ssl支持重新编译了python源代码.当我尝试import ssl使用我的python解释器时,它确实有效,但是当我在服务器上运行代码时,它不起作用.错误日志是这样的:

import _ssl#如果我们无法导入它,让错误传播

看起来很奇怪,不是吗?我的操作系统是Debian Linux发行版.我已经尝试过各种各样的方法,我可以在互联网上找到几天,有谁可以帮助我摆脱这个麻烦?


我试图直接在服务器代码中"导入_ssl",但它提醒我:

>>>callstack
Traceback (most recent call last):
  File "./script/main.py", line 85, in process
    net_flag = net_api_process()
  File "./script/core/netbase/interface.py", line 96, in net_api_process
    flag1 = network.instance().process()
  File "./script/core/netbase/network.py", line 271, in process
    if network.process(max_events):
  File "./script/core/netbase/network.py", line 75, in on_incomin_stream
    self.on_package(buf)
  File "./script/core/netbase/network.py", line 78, in on_package
    self.f_on_package(self, buf)
  File "./script/client/behavior.py", line 68, in on_package
    handler.OnPackage(pack, cmd, conn.m_uid, conn)
  File "./script/client/handler.py", line 288, in OnPackage
    func(uid, conn, pack)
  File "./script/logic/user_info/modify.py", line …
Run Code Online (Sandbox Code Playgroud)

python ssl https httpserver

5
推荐指数
1
解决办法
1万
查看次数

无法在具有python http服务器的浏览器中查看文件

我正在使用命令为远程计算机上的文件夹创建python httpserver:

python -m SimpleHTTPServer 9999
Run Code Online (Sandbox Code Playgroud)

但是我无法使用此功能在浏览器中查看文件。单击链接后,文件即被下载。有没有一种方法可以创建服务器,以便我只能在浏览器中查看文件。

python browser httpserver

5
推荐指数
2
解决办法
2130
查看次数

为什么缓存控制请求的HTTP头?

我最近浏览了这篇文章.它说不仅响应,请求还可以包括cache-control选项.

虽然我明白,它可以被服务器响应有意义地使用,我不清楚理解为什么它们在请求中是需要的.不幸的是,我在互联网上找不到任何能解决我问题的方法.

有谁有想法?

http httpclient cache-control http-caching httpserver

5
推荐指数
1
解决办法
1226
查看次数

在VSCode中运行烧瓶每次都会导致HTTPServer.serve_forever(self)断点

我创建了一个Flask应用程序并开始构建我的项目,但是当我在任何文件中使用断点进行调试时,vscode将自动停止HTTPServer.serve_forever(self)在flask默认模块中的这一行.

事情很烦人,因为它会跳到这一行并忽略我原来的断点,让我很难调试.

任何的想法?

launch.json

{
    "name": "Python: Custom Flask",
    "type": "python",
    "request": "launch",
    "program": "${workspaceFolder}/venv/bin/activate",
    "module": "flask",
    "env": {
        "ENV": ".local"
    },
    "args": [
    "run",
    ]
}
Run Code Online (Sandbox Code Playgroud)

serving.py

def serve_forever(self):
    self.shutdown_signal = False
    try:
        HTTPServer.serve_forever(self) # <- Always stop on this line
    except KeyboardInterrupt:
        pass
    finally:
        self.server_close()
Run Code Online (Sandbox Code Playgroud)

app.py

from flask import app
app = Flask(__name__)

@app.route('/')
def index():
    return "OK"

app.run()
Run Code Online (Sandbox Code Playgroud)

python httpserver flask visual-studio-code vscode-debugger

5
推荐指数
1
解决办法
202
查看次数