UNDERSTANDING HTTP REQUESTS AND RESPONSES

1.

the preferred communication approach in iOSis HTTP. The most convenient networking APIs provided in iOS are geared toward HTTP, the HTTP APIs are the most thoroughly documented, and the high level HTTP APIs are well integrated into the run loop-based architecture of an iOS application. It is no wonder that HTTP and HTTPS are the workhorse protocols of iOS network communications.


2.

INTRODUCING HTTP

There were three major innovations in Berners-Lee’s original proposal: HTML, HTTP, and the URL. 

HTML defined a way to add styling to text, 

HTTP defined a way to convey data between server and client, 

and theURL defined a way to uniquely locate a resource across a network of machines.


3.

UNDERSTANDING HTTP REQUESTS AND RESPONSES


the sequence of steps in a simple HTTP request.:

The client establishes a TCP connection to the server and then sends an HTTP request. The server subsequently responds to the request by sending a HTTP response over the same TCP connection. The client can then reuse the TCP connection for another request or close it. 


The most significant difference between HTTP and HTTPS is during the connection establishment phase of the conversation. After the TCP connection is made but before HTTP requests are transmitted, an SSL session must be established between the client and the server. SSL session establishment includes various stages: the client and server negotiating over which ciphers to use, exchanging public keys, validating the negotiation, and optionally validating identity. After the SSL session is established, all the data transmitted over the TCP connection will be encrypted.


3.

A URL is typically composed of five components, as shown in Figure 3-2.

  • Protocol — The protocol component specifies which application layer protocol to use to communicate to the server. If you’ve been around the web for a while, you may remember using ftp as a protocol in addition to http. The dominance of http has led to the near extinction of pre-HTTP protocol usage. Another commonly used protocol in iOS apps is the file protocol. file requests are used to retrieve resources in the local filesystem within the apps sandbox. If you create an NSURL object using a string without a protocol, it defaults to the file protocol.

  • Hostname — The hostname portion of the URL specifies the TCP hostname or IP address of the host containing the wanted resource. If the protocol of the URL is FILE, then this component and the port component must be omitted. The exception to the preceding rule about a single URL referencing a unique resource is broken when relative or local hostnames are used. For example, if you uselocalhost as the hostname, the URL refers to the local machine; therefore, the same URL can refer to different resources on different machines.
  • Port — The port portion of the URL specifies the TCP port to which the client should connect. If omitted the client uses the default port for the specified protocol: 80 for HTTP and 443 for HTTPS. It is best practice to use these port values for apps running on devices outside networks you control because some network proxies and firewalls will block nonstandard port numbers for security or privacy reasons.
  • Absolute-path — The absolute-path component specifies the path to the network resource as if the HTTP server was drilling down into a directory tree. The absolute-path may include any number of path components each separated by the forward slash (/) character. An absolute-path may not contain a question mark, space, carriage-return, or line-feed characters. Many REST services use path components as a means to pass values to uniquely identify an entity stored in a database. For example, a path of/customer/456/address/0 would specify the address at index 0 for the customer with an identifier of 456.
  • Query — The last component of a URL is the query string. This value is separated from the absolute-path by a question mark (?). By convention multiple query parameters are each separated by an ampersand (&) character. The query string may not contain carriage return, space, or line-feed characters.


image

4
An HTTP request consists of three parts: 
the request line, the request headers, and the request body.

GET /search?source=ig&hl=en&rlz=&q=ios&btnG=Google+Search HTTP/1.1 
Host: www.google.com 
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0)...
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en,en-us;q=0.7,en-ca;q=0.3 
Accept-Encoding: gzip, deflate 
Connection: keep-alive 
Referer: http://www.google.com/ig?hl=en&source=webhp 
Cookie: PREF=ID=fdf9979...


METHOD STANDARD USES
GET Retrieves a piece of content, or entity in HTTP terminology, from the server. GET requests usually don’t contain a request body, but it is allowed. Some network caching appliances will cache only GETresponses. GET requests usually do not cause data changes on the server.
POST Updates an entity with data provided by the client. A POST request usually has information in the body of the request that is used by the application server. POST requests are considered to be non-idempotent, meaning that if more than one request is processed, the result is different than if only one request is processed.
HEAD Retrieves metadata about a response without retrieving the entire contents of the response. This method is usually used to check a server for recent content changes without having to retrieve the full content.
PUT Adds an entity with data provided by the client. A PUT request usually has information in the body of the request that is used by the application server to create the new entity. Usually, PUT requests are considered to be idempotent, meaning that the request can be repeatedly applied with the same results.
DELETE Removes an entity based on contents of the URI or request body provided by the client. DELETE requests are most frequently used in REST service interfaces.

http://my.safaribooksonline.com/book/-/9781118417164/firstchapter#X2ludGVybmFsX0h0bWxWaWV3P3htbGlkPTk3ODExMTg0MTcxNjQlMkZzZWMxMF9odG1sJnF1ZXJ5PQ==


5.

Response Contents

After the HTTP server and any application servers supporting it finish processing the request, an HTTP response is returned to the client over the same TCP socket. An HTTP response is structured similarly to an HTTP request with the first line being the status line, followed by headers, and a response body. The following code shows a sample HTTP response.

HTTP/1.1 200 OK 
Date: Tue, 27 Mar 2012 12:59:18 GMT 
Expires: -1 
Cache-Control: private, max-age=0 
Content-Type: text/html; charset=UTF-8 
Content-Encoding: gzip 
Transfer-Encoding: chunked 
Server: gws
 
<!doctype html><html itemscope="itemscope"
itemtype="http://schema.org/WebPage">
<head><meta itemprop="image" content="/images/google_favicon_128.png"/>
<title>ios - Google Search</title>
<script>window.google={kEI:"prlxT5qtNqe70AHh873aAQ",
getEI:function(a){var b;
while(a&&!(a.getAttribute&&(b=a.getAttribute("eid"

In iOS’s URL loading system, the NSURLResponse object and its subclass NSHTTPURLResponse encapsulate the data returned from a request. There are two objects in this hierarchy because the URL loading can fulfill requests for data based on non-HTTP URLs. For example, a request for a file:// URL will not contain any headers.

在使用Python来安装geopandas包时,由于geopandas依赖于几个其他的Python库(如GDAL, Fiona, Pyproj, Shapely等),因此安装过程可能需要一些额外的步骤。以下是一个基本的安装指南,适用于大多数用户: 使用pip安装 确保Python和pip已安装: 首先,确保你的计算机上已安装了Python和pip。pip是Python的包管理工具,用于安装和管理Python包。 安装依赖库: 由于geopandas依赖于GDAL, Fiona, Pyproj, Shapely等库,你可能需要先安装这些库。通常,你可以通过pip直接安装这些库,但有时候可能需要从其他源下载预编译的二进制包(wheel文件),特别是GDAL和Fiona,因为它们可能包含一些系统级的依赖。 bash pip install GDAL Fiona Pyproj Shapely 注意:在某些系统上,直接使用pip安装GDAL和Fiona可能会遇到问题,因为它们需要编译一些C/C++代码。如果遇到问题,你可以考虑使用conda(一个Python包、依赖和环境管理器)来安装这些库,或者从Unofficial Windows Binaries for Python Extension Packages这样的网站下载预编译的wheel文件。 安装geopandas: 在安装了所有依赖库之后,你可以使用pip来安装geopandas。 bash pip install geopandas 使用conda安装 如果你正在使用conda作为你的Python包管理器,那么安装geopandas和它的依赖可能会更简单一些。 创建一个新的conda环境(可选,但推荐): bash conda create -n geoenv python=3.x anaconda conda activate geoenv 其中3.x是你希望使用的Python版本。 安装geopandas: 使用conda-forge频道来安装geopandas,因为它提供了许多地理空间相关的包。 bash conda install -c conda-forge geopandas 这条命令会自动安装geopandas及其所有依赖。 注意事项 如果你在安装过程中遇到任何问题,比如编译错误或依赖问题,请检查你的Python版本和pip/conda的版本是否是最新的,或者尝试在不同的环境中安装。 某些库(如GDAL)可能需要额外的系统级依赖,如地理空间库(如PROJ和GEOS)。这些依赖可能需要单独安装,具体取决于你的操作系统。 如果你在Windows上遇到问题,并且pip安装失败,尝试从Unofficial Windows Binaries for Python Extension Packages网站下载相应的wheel文件,并使用pip进行安装。 脚本示例 虽然你的问题主要是关于如何安装geopandas,但如果你想要一个Python脚本来重命名文件夹下的文件,在原始名字前面加上字符串"geopandas",以下是一个简单的示例: python import os # 指定文件夹路径 folder_path = 'path/to/your/folder' # 遍历文件夹中的文件 for filename in os.listdir(folder_path): # 构造原始文件路径 old_file_path = os.path.join(folder_path, filename) # 构造新文件名 new_filename = 'geopandas_' + filename # 构造新文件路径 new_file_path = os.path.join(folder_path, new_filename) # 重命名文件 os.rename(old_file_path, new_file_path) print(f'Renamed "{filename}" to "{new_filename}"') 请确保将'path/to/your/folder'替换为你想要重命名文件的实际文件夹路径。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值