Read response body to string. return empty string if response has no body
499049
public String readToText() {
        Charset charset = getCharset();
        try (InputStream in = body();
             Reader reader = new InputStreamReader(in, charset)) {
            return Readers.readAll(reader);
        } catch (IOException e) {
            throw new RequestsException(e);
        } finally {
            close();
        }
    }
633876
def parse_response(response)
      unless response.body
        raise ResponseError, 'PaynetEasy response is empty'
      end

      # Change hash format from {'key' => ['value']} to {'key' => 'value'} in map block
      response_fields = Hash[CGI.parse(response.body).map {|key, value| [key, value.first]}]

      Response.new response_fields
    end
735677
private static String getResponseStringData(InputStream is, String charset) throws IOException {
    ByteArrayOutputStream respDataStream = new ByteArrayOutputStream();
    String result;
    try {
      byte[] b = new byte[8192];
      int len;
      while (true) {
        len = is.read(b);
        if (len <= 0) {
          is.close();
          break;
        }
        respDataStream.write(b, 0, len);
      }
      result = respDataStream.toString(charset);
    } finally {
      respDataStream.close();
    }
    return result;
  }
1355454
def _decode_response(response):
    
    status_code = response.status_code

    message = "Status code " + str(status_code)
    try:
      message = CraftAIClient._parse_body(response)["message"]
    except (CraftAiInternalError, KeyError, TypeError):
      pass

    if status_code in [200, 201, 204, 207]:
      return CraftAIClient._parse_body(response)
    else:
      raise CraftAIClient._get_error_from_status(status_code, message)
    return None
195456
async def text(self,
                   encoding: Optional[str]=None, errors: str='strict') -> str:
        """"""
        if self._body is None:
            await self.read()

        if encoding is None:
            encoding = self.get_encoding()

        return self._body.decode(encoding, errors=errors)
894204
def decode_response(client_message, to_object=None):
    
    parameters = dict(response=None)
    if not client_message.read_bool():
        parameters['response'] = to_object(client_message.read_data())
    return parameters
450659
public String getResponseBody() {
        String responseStr = "";
        if (lastResponseStream == null) {
            logger.error("Unable to parse JSON from empty response!");
        } else {
            Scanner s = new Scanner(lastResponseStream);
            s.useDelimiter("\\A");
            responseStr = (s.hasNext()) ? s.next() : "";
            s.close();
        }
        return responseStr;
    }
86310
async def parse_result(response, response_type=None, *, encoding="utf-8"):
    
    if response_type is None:
        ct = response.headers.get("content-type")
        if ct is None:
            cl = response.headers.get("content-length")
            if cl is None or cl == "0":
                return ""
            raise TypeError(
                "Cannot auto-detect response type "
                "due to missing Content-Type header."
            )
        main_type, sub_type, extras = parse_content_type(ct)
        if sub_type == "json":
            response_type = "json"
        elif sub_type == "x-tar":
            response_type = "tar"
        elif (main_type, sub_type) == ("text", "plain"):
            response_type = "text"
            encoding = extras.get("charset", encoding)
        else:
            raise TypeError("Unrecognized response type: {ct}".format(ct=ct))
    if "tar" == response_type:
        what = await response.read()
        return tarfile.open(mode="r", fileobj=BytesIO(what))
    if "json" == response_type:
        data = await response.json(encoding=encoding)
    elif "text" == response_type:
        data = await response.text(encoding=encoding)
    else:
        data = await response.read()
    return data
262863
def _data_from_response(self, resp_body, key=None):
        
        if key:
            data = resp_body.get(key)
        else:
            data = resp_body.get(self.plural_response_key, resp_body)
        # NOTE(ja): some services, such as keystone returns values as list as
        # {"values": [ ... ]} unlike other services which just return the
        # list.
        if isinstance(data, dict):
            try:
                data = data["values"]
            except KeyError:
                pass
        return data
294822
def getBody(self):
        
        data = None
        try:
            data = json.loads(self.request.body)
        except:
            data = json.loads(urllib.unquote_plus(self.request.body))
        return data
285858
def decode_response(client_message, to_object=None):
    
    parameters = dict(response=None)
    parameters['response'] = client_message.read_long()
    return parameters
1317318
def _read_response(self, response):
        
        self.name = response['name']
        self.description = response['description']
        self.autoJoin = response['autoJoin']
        self.realm = response['realm']
        self.realmAttributes = response.get('realmAttributes', None)
1036369
def _as_json(self, response):
        
        # Assume ClientResponse has "body", and otherwise it's a requests.Response
        content = response.text() if hasattr(response, "body") else response.text
        try:
            return json.loads(content)
        except ValueError:
            raise DeserializationError(
                "Error occurred in deserializing the response body.")
614919
def decode_body(headers: MutableMapping, body: bytes) -> dict:
    

    type_, encoding = parse_content_type(headers)
    decoded_body = body.decode(encoding)

    # There is one api that just returns `ok` instead of json. In order to have a consistent API we decided to modify the returned payload into a dict.
    if type_ == "application/json":
        payload = json.loads(decoded_body)
    else:
        if decoded_body == "ok":
            payload = {"ok": True}
        else:
            payload = {"ok": False, "data": decoded_body}

    return payload
992038
private function readResponseBodyString($responseBodyString)
    {
        $responseLines = array_filter(array_map(function ($value) {
            return trim($value);
        }, explode("\n", $responseBodyString)));

        $result = [];
        foreach ($responseLines as $responseLine) {
            $responseParts = explode('=', $responseLine);
            $result[strtolower($responseParts[0])] = $responseParts[1];
        }

        $status = (int) $result['status'];
        unset($result['status']);
        $result['success'] = ($status >= 0) ? true : false;
        $result['statusCode'] = $status;

        return $result;
    }
984987
def parse_response(resp)
      body = JSON.parse(resp.body)
      if body['error']
        raise Apilayer::Error.new(
          body['error']['info'],
          body['error']['code']
        )
      else
        body
      end
    end
778700
def read_response(self, response=None):
        '''
        '''
        _logger.debug('Reading header.')

        if response is None:
            response = Response()

        header_lines = []
        bytes_read = 0

        while True:
            try:
                data = yield from self._connection.readline()
            except ValueError as error:
                raise ProtocolError(
                    'Invalid header: {0}'.format(error)) from error

            self._data_event_dispatcher.notify_read(data)

            if not data.endswith(b'\n'):
                raise NetworkError('Connection closed.')
            elif data in (b'\r\n', b'\n'):
                break

            header_lines.append(data)
            assert data.endswith(b'\n')

            bytes_read += len(data)

            if bytes_read > 32768:
                raise ProtocolError('Header too big.')

        if not header_lines:
            raise ProtocolError('No header received.')

        response.parse(b''.join(header_lines))

        return response