   (with-current-buffer (or buffer (current-buffer))
     (let* ((column-num (+ 1 (ycmd--column-in-bytes)))
            (line-num (line-number-at-pos (point)))
-           (full-path (or (buffer-file-name) ""))
-           (file-contents (buffer-substring-no-properties (point-min) (point-max)))
+           (full-path (ycmd--encode-string (or (buffer-file-name) "")))
+           (file-contents (ycmd--encode-string
+                           (buffer-substring-no-properties
+                            (point-min) (point-max))))
            (file-types (or (ycmd-major-mode-to-file-types major-mode)
                            '("generic"))))
       `(("file_data" .


(defun ycmd--get-request-hmac (method path body)
  "Generate HMAC for request from METHOD, PATH and BODY."
  (let* ((hmac-secret (encode-coding-string
                       ycmd--hmac-secret 'utf-8 t))
         (joined-hmac-input
          (mapconcat
           (lambda (val) (ycmd--hmac-function
                          (encode-coding-string val 'utf-8 t)
                          hmac-secret))
           `(,method ,path ,(or body "")) "")))
    (ycmd--hmac-function joined-hmac-input hmac-secret)))

(defun* ycmd--request (location
                       content

  (- (position-bytes (point))
     (position-bytes (line-beginning-position))))

(defun ycmd--encode-string (s)
  "Encode string S."
  (if (eval-when-compile
        (version-list-< (version-to-list emacs-version) '(25)))
      s
    (encode-coding-string s 'utf-8 t)))

(defun ycmd--standard-content (&optional buffer)
  "Generate the 'standard' content for ycmd posts.

