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源码

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值