title: Why is my POST method returning "Unauthorized"? C#
body: <p><a href="http://static.pmmlabs.ru/OpenPeriscope/" rel="nofollow noreferrer">http://static.pmmlabs.ru/OpenPeriscope/</a></p>
  
  <p>I follow the documentation under "Authentication" where they provide examples and error responses. I am currently receiving this error message when I call my POST-method:</p>
  
  <pre><code>401 Unauthorized This endpoint requires authentication and no cookie value was provided, or is invalid
  </code></pre>
  
  <p>The token should absolutely contain the correct value so I assume it has to be something with the code. This is my current code:</p>
  
  <pre><code>var client = new HttpClient();
  client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
  string json = "{" +
              "\"bundle_id\":\"\"," +
              "\"phone_number\":\"\"," +
              "\"session_key\":\"" + key + "\"," +
              "\"session_secret\":\"" + secret + "\"," +
              "\"user_id\":\"" + userid + "\"," +
              "\"user_name\":\"" + name + "\"," +
                          "\"vendor_id\":\"81EA8A9B-2950-40CD-9365-40535404DDE4\"" +
                          "}";
  var content = new StringContent(json);
  System.Diagnostics.Debug.WriteLine(json);
  var response = await client.PostAsync("https://api.periscope.tv/api/v2/loginTwitter", content);
  var responseJson = await response.Content.ReadAsStringAsync();
  System.Diagnostics.Debug.WriteLine(responseJson);
  </code></pre>
  
  <p>The JSON I put together is also valid. If I write it out in the log it looks like this:</p>
  
  <pre><code>{"bundle_id":"","phone_number":"","session_key":"752365274-loPQJPpyAtwuqcJJtTqk7KlRgbdGgVQ5ahBWuItr","session_secret":"2hY9kLYCwKC3rIGGMlCt523uOy08zc8SEc7w6WSlLLViD","user_id":"752365274","user_name":"My username","vendor_id":"81EA8A9B-2950-40CD-9365-40535404DDE4"}
  </code></pre>
  
  <p>I came across a post where a user successfully made it work but it was with "HttpWebRequest" method that I cannot use because I am coding in Xamarin Forms (PCL). <a href="https://stackoverflow.com/questions/39684558/using-twitter-login-api">Using Twitter login API</a></p>
  
  <p>If you check his answer to his own post you can see the sample code.</p>
  
  <p>How can I adjust my current code in order to successfully get the JSON response?</p>
  
  <p>UPDATE:</p>
  
  <p>Parameters/tokens should be correct. Been trying with different solutions/codestructures but it keeps giving me "Unauthorized". This is the last code I tried to use (tried to mimic the project that I linked that works):</p>
  
  <pre><code>        var client = new HttpClient();
          var parameters = new Dictionary&lt;string, string&gt; {
              { "session_secret", secret},
              { "user_id", userid},
              { "phone_number", ""},
              { "vendor_id", ""},
              { "bundle_id", "com.bountylabs.periscope"},
              { "session_key", key},
              { "user_name", username}
          };
  
          var jsonRequest = JsonConvert.SerializeObject(parameters);
          MemoryStream jsonStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(jsonRequest));
          HttpContent content = new StreamContent(jsonStream);
  
          var response = await client.PostAsync("https://api.periscope.tv/api/v2/loginTwitter", content);
          var responseJson = await response.Content.ReadAsStreamAsync();
          var streamReader = new StreamReader(responseJson);
          var str = streamReader.ReadToEnd();
          System.Diagnostics.Debug.WriteLine(str);
  </code></pre>