Library Search
结果页

HTTP 服务器入门 — Hello World + 文件读写

在 元器件 / 技术栈 / 知识库 中找到 16 个匹配结果。

返回文档库
技术栈

技术栈

8 个
查看全部
PHP `bash php -S localhost:8000 ``` 浏览器访问 `http://localhost:8000/hello.php`,页面显示: ``` Hello, World! 今天的日期是:2026-01-15 ``` ## 方式三:嵌入 HTML 创建 `index.php`: ```php <!DOCTYPE html> <html> <head><title>PHP… 3% Java # Java Hello World — Spring Boot REST API ## 目标 用 Spring Boot 3 创建一个 RESTful Web 服务,返回 JSON 格式的 "Hello World"。 ## 完整代码 ```java // HelloWorldApplication.java package com.example.demo; import org.sp… 3% Symfony stractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\Routing\Annotation\Route; class HelloController extends AbstractController { #[Route('/api/hello', name:… 3% Node.js ` $ node app.js API server listening at http://localhost:3000 ``` | 请求 | 响应 | |------|------| | `GET /users` | `{"total":2,"data":[{...},{...}]}` | | `POST /users` | `{"id":3,"name":"Charlie","email"… 2% Spring Boot # Spring Boot Hello World REST API ## 目标 创建一个最简单的 Spring Boot REST API,返回 "Hello, World!" JSON 响应。 ## 完整代码 ### 1. 主应用类 `DemoApplication.java` ```java package com.example.demo; import org.springfr… 2% Slim ex.php` — 入口文件** ```php <?php use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Factory\AppFactory; require __DIR__ . '/../vendor/… 2% Phalcon class HelloController extends Controller { /** * GET /hello — JSON API 端点 */ public function indexAction(): Response { return $this->response ->setContentType… 2% Yii ### 完整代码 **1. 使用 Gii 生成控制器(可选)** 访问 `http://localhost:8080/gii`,使用 Controller Generator。 **2. 手动创建 `controllers/HelloController.php`** ```php <?php namespace app\controllers; use Yii; use yii\w… 2%
知识库

知识库

8 个
Hello World `bash php -S localhost:8000 ``` 浏览器访问 `http://localhost:8000/hello.php`,页面显示: ``` Hello, World! 今天的日期是:2026-01-15 ``` ## 方式三:嵌入 HTML 创建 `index.php`: ```php <!DOCTYPE html> <html> <head><title>PHP… 3% Hello World — GET 请求与 JSON 解析 目标 发送一个 GET 请求到公开 API,解析 JSON 响应,并处理常见 HTTP 状态码。 ## 完整代码 ```python import requests # 1. 基础 GET 请求 url = "https://api.github.com/repos/psf/requests" response = requests.get(url) # 2. 检查状态码 print(f… 3% Hello World - REST API ex.php` — 入口文件** ```php <?php use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Factory\AppFactory; require __DIR__ . '/../vendor/… 2% Hello World - 组件与双向绑定 ## 目标 创建 Angular 应用,展示组件、双向绑定、服务注入、路由和 HTTP 请求。 ## 完整代码 ### 项目创建 ```bash ng new angular-demo --routing --style=scss cd angular-demo ng generate component counter ng generate component todo ng gene… 2% Hello World - MVC 控制器 class HelloController extends Controller { /** * GET /hello — JSON API 端点 */ public function indexAction(): Response { return $this->response ->setContentType… 2% 01-hello-world-基础语法 # ===== 7. 文件读写 ===== with open("demo.txt", "w", encoding="utf-8") as f: f.write("Hello from Python!\n") f.write(f"Generated by {name}\n") with open("demo.txt", "r", encoding="utf-8") as f:… 2% Hello World - 控制器与视图 ### 完整代码 **1. 使用 Gii 生成控制器(可选)** 访问 `http://localhost:8080/gii`,使用 Controller Generator。 **2. 手动创建 `controllers/HelloController.php`** ```php <?php namespace app\controllers; use Yii; use yii\w… 2% Hello World — 爬取图书信息 d:爬取图书信息 ## 目标 爬取 [books.toscrape.com](http://books.toscrape.com) 上的图书标题、价格、评级,并保存为 JSON。 ## 完整代码 ### 1. 创建项目 ```bash scrapy startproject bookscraper cd bookscraper scrapy genspider books books.to… 2%