Atitit httpclient Interface Overview rest directory 1. Httpclient use the http protocol client library and technology 1 2 feature purpose why 2 2.1. Upload and download files 2

Atitit httpclient rest Interface Overview

 

 

table of Contents

1. Httpclient using http protocol client library and art methods 1

2. Functional use why 2

2.1. Upload and download files 2

2.2 Text html; reptiles collected 2

2.3. Submit the form etc 2

3. The specific procedure how 2

4. Cross-language pattern curl using 2 Cli

5. api mode using different languages ​​and environments 3

5.1. Java httpclient 3

5.2. Python 3

5.3. Js browser environment ajax 3

5.4. Js node environment http module 3

5.5. Php 3

5.6. Net of httpclient 3

6. Python realized 4

6.1. Import urllib.request error, seemingly for gzip support is not good 4

6.2. Use requests to module 4

7. Rf 4

 

 

  1. Httpclient using the http protocol client library and technical methods

 

Get post method

 

  1. Feature purpose why
    1. Upload and download files
    2.  Text html; reptiles acquisition
    3. Submit forms, etc.
  2. How specific processes

HTTPServer connection, the received byte stream, if text may require transcoding (GBK UTF) to a string

 

  1. Use of cross-language Cli mode 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);

Doctrine default curl use gbk code reading. . So if the url output gbk

Iconv using transform coding or not ati tested.

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

  1. Use api mode in different languages ​​and environments
    1. Java httpclient

 

// get execution request.

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

// Get the response entity

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

return html;

    1. Python  
    2. Js browser environment ajax
    3. Js node environment http module
    4. Php 
    5. Net of httpclient

 

  1. Python implementation
    1. Import urllib.request  error, seemingly for good support 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. Use requests module  can be

 

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

print(r.text)

 

 

 

  1. Rf

Atitit python get html source code

 

Guess you like

Origin blog.csdn.net/attilax/article/details/91863567