python perl curl 模拟get请求

curl:

curl http://192.168.137.1:8000/api2/ping/

node2:/root#curl http://192.168.137.1:8000/api2/ping/
"pong"node2:/root#



perl 版本:

use  LWP::UserAgent; 
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
$ua->agent("Mozilla/8.0");
my $host = "http://192.168.137.1:8000/api2/ping/";
my $response = $ua->get($host);
   $ua->default_headers;
  if ($response->is_success) {
      print $response->decoded_content;  # or whatever
   }
    else {
    die $response->status_line;
}


python 版本:

# !/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import urllib
import cookielib
import json
import httplib
url = 'http://192.168.137.1:8000/api2/ping/'
conn = httplib.HTTPConnection('192.168.137.1', 8000)
header={}
conn.request('GET', url, '', header)
response = conn.getresponse()
res = response.read()
print res

C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/Django/a1.py
"pong"

import json
import urllib
import urllib2
url = "https://www.zjcap.cn/web/noauth?productSn=1079&method=%2Fproduct%2Fdetail&platform=web&_=1509514340879"
req = urllib2.Request(url)
print req
print type(req)

res_data = urllib2.urlopen(req)
res = res_data.read()
print res
print type(res)


 
 

你可能感兴趣的:(python,perl,curl,模拟各种请求)