title: How to pass Accept: application json header in call, post request Laravel 5.1
body: <p>How do I pass the "Accept: application/json" in request when testing:</p>
  
  <p>for eg:</p>
  
  <pre><code>$response = $this-&gt;post($route, $data, ['Accept: application/json']);
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>$response = $this-&gt;call('post' $route, $data, [], [], ['Accept: application/json']);
  </code></pre>
  
  <p>I want to invoke <code>$this-&gt;wantsJson()</code> in the FormRequest class:</p>
  
  <pre><code>/**
       * Get the proper failed validation response for the request.
       *
       * @param  array  $errors
       * @return \Symfony\Component\HttpFoundation\Response
       */
      public function response(array $errors)
      {
          if ($this-&gt;ajax() || $this-&gt;wantsJson()) {
              return new JsonResponse($errors, 422);
          }
  
          return $this-&gt;redirector-&gt;to($this-&gt;getRedirectUrl())
                                          -&gt;withInput($this-&gt;except($this-&gt;dontFlash))
                                          -&gt;withErrors($errors, $this-&gt;errorBag);
      }
  </code></pre>