Atitit httpclient 概述 rest接口 目录 1. Httpclient 利用http协议的client类库与技术方法 1 2. 功能用途 why 2 2.1. 上传下载文件 2

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模式 3

5.1. Java httpclient 3

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的实现 4

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

6.2. 使用 requests模块 即可 4

7. Rf 4

 

 

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

 

Get post 方法

 

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

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

 

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

 command="D:\\prgrm\\bin\\curl.exe  http://localhost:8080/reg";

 

String rzt = IOUtils.toString(Runtime.getRuntime().exec(command).getInputStream(), "gbk");

System.out.println(rzt);

主义默认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
    3. Js node环境 http模块
    4. Php 
    5. 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源码

 

猜你喜欢

转载自blog.csdn.net/attilax/article/details/91863567
今日推荐