zoukankan      html  css  js  c++  java
  • requests get发送 json数据


    http://192.168.137.2:9200/


    GET /library/books/_mget  
    {  
       "ids" : [ "1", "4" ]  
    }




    {
      "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": "4",
          "_version": 1,
          "found": true,
          "_source": {
            "title": "Thinking in Python",
            "price": 22,
            "preview": "Welcome! Are you completely new to programming? If not then we presume you will be looking for information about why and how to get started with Python. Fortunately an experienced programmer in any programming language (whatever it may be) can pick up Python very quickly. It's also easy for beginners to use and learn",
            "publish_date": "2015-07-11"
          }
        }
      ]
    }






    python requests get 发送json数据:


    # !/usr/bin/env python
    # -*- coding: utf-8 -*-
    import urllib2
    import urllib
    import cookielib
    import json
    import httplib
    import re
    import requests
    s=requests.session()
    #response = s.get(url, params=datas, **kwargs)
    headers = {'Content-Type': 'application/json'}    ## headers中添加上content-type这个参数,指定为json格式
    datas={
       "ids" : [ "1", "4" ]
    }
    response = s.get('http://192.168.137.2:9200/library/books/_mget',headers=headers, data=json.dumps(datas))
    print response.text




    C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/Django/a16.py
    {"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":"4","_version":1,"found":true,"_source":{ "title":"Thinking in Python","price":22,"preview":"Welcome! Are you completely new to programming? If not then we presume you will be looking for information about why and how to get started with Python. Fortunately an experienced programmer in any programming language (whatever it may be) can pick up Python very quickly. It's also easy for beginners to use and learn" , "publish_date":"2015-07-11" }}]}


    Process finished with exit code 0

  • 相关阅读:
    阿里安全归零实验室招聘各路大牛!offer好说!
    露脸!钉钉通过SOC2隐私性原则审计,安全和隐私保护达超一流国际标准
    BAT齐聚阿里安全-ASRC生态大会:呼吁联合共建网络安全白色产业链
    v3-4_-vict-、-vinc-胜利,征服
    Grammar01 语法七要素之一_词类
    Grammar00_英语学习铁律
    SpokenEnglish01_ When's it due?
    SpringBoot31 重识Spring01-环境搭建、Actuator监控、属性配置、多环境配置
    Shrio04 自定义Realm
    Shrio03 Authenticator、配置多个Realm、SecurityManager认证策略
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349192.html
Copyright © 2011-2022 走看看