Atitit httpclient 概述  rest接口

Atitit httpclient 概述  rest接口

 

 

目录

1. Httpclient 利用http协议的client类库与技术方法 1

2. 功能用途 why 2

2.1. 上传下载文件 2

2.2. 文本html  ;爬虫采集 2

2.3. 提交表单等 2

3. 具体流程how 2

4. 跨语言Cli模式 curl的使用 2

5. 不同语言与环境下的使用 api模式 2

5.1. Java httpclient 2

5.2. Python 3

5.3. Js 浏览器环境ajax 3

5.4. Js node环境 http模块 3

5.5. Php 3

5.6. Net 的httpclient 3

6. Python的实现 3

6.1. import urllib.request 报错 ,貌似对gzip支持不好 3

6.2. 使用 requests模块 即可 4

7. Rf 4

 

 

  1. Httpclient 利用http协议的client类库与技术方法

 

Get post 方法

 

http server  ::java servlet

 

  1. 功能用途 why
    1. 上传下载文件
    2.  文本html  ;爬虫采集
    3. 提交表单等
  2. 具体流程how

连接httpserver ,接受字节流,如果是文本,可能需要转码(gbk utf)为字符串

 

传入一个url,得到输出值html json

 

  1. 跨语言Cli模式 curl的使用

 "D:\\prgrm\\bin\\curl.exe  http://localhost:8088/list.json";

 

 主义默认curl使用gbk编码读取。。所以url输出要是gbk

或者使用iconv转换编码 not ati tested.

curl http://www.baidu.com | iconv -f gb2312 -t utf-8 iconv

  1. 不同语言与环境下的使用 api模式
    1. Java httpclient

 

// 执行get请求.

CloseableHttpResponse response = HttpClients.createDefault().execute(new HttpGet(url));

// 获取响应实体

String html = EntityUtils.toString(response.getEntity());

return html;

    1. Python  
    2. Js 浏览器环境ajax

 

    1. Js node环境 http模块

跨语言curl工具

    1. Php 
    2. Net 的httpclient

 

  1. Python的实现
    1. import urllib.request 报错 ,貌似对gzip支持不好



from bs4 import BeautifulSoup, Comment
import urllib.request
import requests
response = urllib.request.urlopen('http://www.qq.com/')
##html = response.read().decode('UTF-8','ignore')
#html = response.read().decode('gb2312','ignore')
# print (html)

 

    1. 使用 requests模块 即可

 

r = requests.get('http://www.qq.com/')

print(r.text)

 

 

 

  1. Rf

Atitit python获取html源码

 

posted @ 2019-06-13 21:08  attilaxAti  阅读(28)  评论(0编辑  收藏  举报