title: HTTP 403 while executing a PUT request
body: <p>I am creating a django rest api, and I'm trying to send JSON data via PUT request from an Android device, using HttpUrlConnection.</p>
  
  <pre><code>URL url = new URL(myurl);
  conn = (HttpURLConnection) url.openConnection();
  conn.setReadTimeout(10000 /* milliseconds */);
  conn.setConnectTimeout(15000 /* milliseconds */);
  conn.setRequestMethod("PUT");
  conn.setDoInput(true);
  conn.setDoOutput(true);
  conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
  conn.setRequestProperty("Accept", "application/json");
  Log.v("Apiput", MainActivity.cookieManager.getCookieStore().getCookies().get(0).toString());
  conn.connect();
  if(conn.getResponseCode() != 200) {
      return "" + conn.getResponseCode();
  }
  OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream());
  osw.write(put);
  osw.flush();
  osw.close();`
  </code></pre>
  
  <p>I know I have to send a csrf token, but I think that I'm sending it already.
  By examining the META in my request I can see the csrf token both in headers and cookies:</p>
  
  <p><code>'HTTP_COOKIE': 'csrftoken=3jLNzfLIu1P5dBH4WWwggHMH7oDQC7Rx;'</code></p>
  
  <p>And in my android device i have a CookieManager that says that the csrf cookie has the same value.</p>
  
  <p><code>V/Apiput﹕ csrftoken=3jLNzfLIu1P5dBH4WWwggHMH7oDQC7Rx</code></p>
  
  <p>I am getting a 403 (Forbidden) Http error besides the user is authenticated (I can make GET Requests)</p>
  
  <p><code>[26/Sep/2015 00:16:04]"PUT /api/works/34/ HTTP/1.1" 403 58</code></p>
  
  <p>With curl I am able to send the request without any problem, with the same user credentials.</p>
  
  <p>I wonder if anyone can tell me what am I doing wrong.</p>
  
  <p>Thanks.</p>