curl perl python get 发送json数据
2017-10-18 13:19
357 查看
get 发送jason 数据 GET /library/books/_mget { "ids" : [ "1", "3" ] } Perl 版: [elk@node01 ~]$ perl a1.pl {"docs":[{"_index":"library","_type":"books","_id":"1","_version":1,"found":true,"_source":{ "title":"Elasticsearch: The Definitive Guide","price":5,"preview":"Elasticsearch is a distributed, scalable, real-time search and analytics engine. It ena‐bles you to search, analyze, and explore your data, often in ways that you did not anticipate at the start of a project. It exists because raw data sitting on a hard drive is just not useful." ,"publish_date":"2015-02-08"}},{"_index":"library","_type":"books","_id":"3","_version":1,"found":true,"_source":{ "title":"Elasticsearch Blueprints","price":9,"preview":"This book starts with the creation of a Google-like web search service, enabling you to generate your own search results. You will then learn how an e-commerce website can be built using Elasticsearch. We will discuss various approaches in getting relevant content up the results, such as relevancy based on how well a query matched the text, time-based recent documents, geographically nearer items, and other frequently used approaches." , "publish_date":"2015-06-01"}}]}[elk@node01 ~]$ cat a1.pl use LWP::UserAgent; use LWP; use Encode; use LWP::Simple; use LWP::UserAgent; use HTTP::Cookies; use HTTP::Headers; use HTTP::Response; use Encode; use URI::Escape; use URI::URL; use JSON; use Data::Dumper; my $ua = LWP::UserAgent->new; $ua->agent("Mozilla/5.0 (Windows NT 6.1; rv:30.0) Gecko/20100101 Firefox/30.0"); my $cookie_jar = HTTP::Cookies->new( file=>'lwp_cookies.txt', autosave=>1, ignore_discard=>1); $ua->cookie_jar($cookie_jar); my $login_url ="http://192.168.137.2:9200/library/books/_mget"; my $post = { "ids" => [ "1", "3" ] }; use JSON qw(encode_json); $json_string = encode_json($post); my $req = HTTP::Request->new( 'GET' => $login_url ); $req->referer("https://wx.qq.com/?&lang=zh_CN"); $req->content_type('application/json; charset=UTF-8') ; #post请求,如果有发送参数,必须要有这句 $req->content("$json_string"); #发送post的参数 my $res = $ua->request($req); print $res->content(); #获取的是响应正文 [elk@node01 ~]$ perl a1.pl {"docs":[{"_index":"library","_type":"books","_id":"1","_version":1,"found":true,"_source":{ "title":"Elasticsearch: The Definitive Guide","price":5,"preview":"Elasticsearch is a distributed, scalable, real-time search and analytics engine. It ena‐bles you to search, analyze, and explore your data, often in ways that you did not anticipate at the start of a project. It exists because raw data sitting on a hard drive is just not useful." ,"publish_date":"2015-02-08"}},{"_index":"library","_type":"books","_id":"3","_version":1,"found":true,"_source":{ "title":"Elasticsearch Blueprints","price":9,"preview":"This book starts with the creation of a Google-like web search service, enabling you to generate your own search results. You will then learn how an e-commerce website can be built using Elasticsearch. We will discuss various approaches in getting relevant content up the results, such as relevancy based on how well a query matched the text, time-based recent documents, geographically nearer items, and other frequently used approaches." , "publish_date":"2015-06-01"}}]}[elk@node01 ~]$ python 版: def get_library(): url = 'http://192.168.137.2:9200/library/books/_mget' data = {"ids" : [ "1", "3" ]} print type(data) data = json.dumps(data) print type(data) request = urllib2.Request(url,data) request.add_header("Content-Type", "application/json") request.add_header("Accept", "application/json") request.get_method = lambda: "GET" # "GET,POST,PUT,DELETE" response = urllib2.urlopen(request) response_txt = response.read() response_header = response.info() print response_txt print response_header C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/Django/a4.py <type 'dict'> <type 'str'> {"docs":[{"_index":"library","_type":"books","_id":"1","_version":1,"found":true,"_source":{ "title":"Elasticsearch: The Definitive Guide","price":5,"preview":"Elasticsearch is a distributed, scalable, real-time search and analytics engine. It ena‐bles you to search, analyze, and explore your data, often in ways that you did not anticipate at the start of a project. It exists because raw data sitting on a hard drive is just not useful." ,"publish_date":"2015-02-08"}}, {"_index":"library","_type":"books","_id":"3","_version":1,"found":true,"_source":{ "title":"Elasticsearch Blueprints","price":9,"preview":"This book starts with the creation of a Google-like web search service, enabling you to generate your own search results. You will then learn how an e-commerce website can be built using Elasticsearch. We will discuss various approaches in getting relevant content up the results, such as relevancy based on how well a query matched the text, time-based recent documents, geographically nearer items, and other frequently used approaches." , "publish_date":"2015-06-01"}}]} Content-Type: application/json; charset=UTF-8 Content-Length: 1087 None Process finished with exit code 0
相关文章推荐
- curl perl python post发送json数据
- perl get 发送json数据
- perl和curl 模拟post 发送json数据
- perl get 发送json数据<2>
- php通过curl post和get发送json数据实例 curl命令转为php源码
- perl 和curl 发送json数据例子
- cjson libcurl 发送请求给python 接受数据和处理数据 参考了一下别人的方法
- Android使用HttpClient以Post、Get请求服务器发送数据的方式(普通和json)
- python实现的json数据以HTTP GET,POST,PUT,DELETE方式页面请求
- libcurl HTTP POST请求向服务器发送json数据
- Android之向中国天气网发送GET请求获取JSON数据实例
- 常规的利用Curl发送json数据到后台SpringBoot+MongoDB测试CRUD
- php中使用curl发送JSON数据
- python实现的json数据以HTTP GET,POST,PUT,DELETE方式页面请求
- python requests 自动管理 cookie 。 get后进行post发送数据---》最简单的刷票
- 浅谈使用Fiddler工具发送post请求(带有json数据)以及get请求(Header方式传参)
- http中get发送json格式数据以及接收方的处理
- python 发送带请求头的json数据
- python实现的json数据以HTTP GET,POST,PUT,DELETE方式页面请求
- php使用curl发送json格式数据实例