title: System.Net.WebException: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse()
body: <p>I want to sent push notification via parse.com and i have webservice like that</p>
  
  <p>[WebMethod]
      public bool pushNotification(string pushMessage) 
      {
          bool isPushMessageSend = false;</p>
  
  <pre><code>    string postString = "";
      string urlpath = "https://api.parse.com/1/push";
      //var httpWebRequest = (HttpWebRequest)WebRequest.Create(urlpath);
  
      System.Net.WebRequest request = System.Net.HttpWebRequest.Create(urlpath);
  
      request.UseDefaultCredentials = true;
  
      request.PreAuthenticate = true;
  
      request.Credentials = CredentialCache.DefaultCredentials;
  
  
  
  
      postString = "{ \"channels\": [ \"Trials\"  ], " +
                       "\"data\" : {\"alert\":\"" + pushMessage + "\"}" +
                       "}";
      request.ContentType = "application/json";
      request.ContentLength = postString.Length;
      request.Headers.Add("APP ID", "My Parse App Id");
      request.Headers.Add("REST API KEY", "My Rest API Key");
      request.Method = "POST";
      StreamWriter requestWriter = new StreamWriter(request.GetRequestStream());
      requestWriter.Write(postString);
      requestWriter.Close();
      //var httpResponse = (HttpWebResponse)request.GetResponse();
      System.Net.WebResponse response = request.GetResponse();
      using (var streamReader = new StreamReader(response.GetResponseStream()))
      {
          var responseText = streamReader.ReadToEnd();
          JObject jObjRes = JObject.Parse(responseText);
          if (Convert.ToString(jObjRes).IndexOf("true") != -1)
          {
              isPushMessageSend = true;
          }
      }
  
      return isPushMessageSend;
  }
  </code></pre>
  
  <p>I had error like this</p>
  
  <pre><code>System.Net.WebException: The remote server returned an error: (401) Unauthorized.
     at System.Net.HttpWebRequest.GetResponse()
     at WebService.pushNotification(String pushMessage) in c:\Users\Hurkan Seyhan\desktop\website3\App_Code\WebService.cs:line 488
  </code></pre>
  
  <p>How can I solve this problem?</p>