title: Xamarin widget button, NameResolutionFailure HttpWebRequest
body: <p>So I am facing what I think is a strange problem.</p>
  <p>I have made a small xamarin app that uses a widget button to POST to a server using HttpWebRequest. Everything works just fine when I use my phone in debug mode trough VS.</p>
  <p>But when I disconnect my phone and try to use the app I get the NameResolutionFailure.</p>
  <p>It is not an DNS issue as it is Tesla motors servers, and it works when debugging.</p>
  <p>As for permissions I have set internet and access network state.</p>
  <p>Anyone know where my problem might be? Is there any other permission sets that needs to be included?</p>
  <p>Any help will be appriciated as I have come to a loss with this one..</p>
  <p>This is where the code gets the NameResolutionFailure error, but not sure if it is related to other problems in settings etc. This only happens from the widget button click, not if i add a button  in the app itself..</p>
  <pre><code>        private static string postToInterface(string methodPosting, string linkExtension, string token = null, string JSON = null)
      {
          try
          {
              //Create the web socket
              HttpWebRequest webSocket = (HttpWebRequest)WebRequest.Create(&quot;https://owner-api.teslamotors.com/&quot; + linkExtension);
              if (token != null)
              {
                  webSocket.Headers.Add(&quot;Authorization&quot;, &quot;Bearer &quot; + token);
              }
  
              webSocket.ContentType = &quot;application/json&quot;;
              webSocket.Method = &quot;POST&quot;;
  
              if (JSON != null)
              {
                  using (var streamWriter = new StreamWriter(webSocket.GetRequestStream()))
                  {
  
                      streamWriter.Write(JSON);
                  }
              }
  
              var httpResponse = (HttpWebResponse)webSocket.GetResponse();
              using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
              {
                  return streamReader.ReadToEnd();
              }
          }
          catch (WebException error)
          {
              HttpWebResponse response = (HttpWebResponse)error.Response;
              return &quot;Error: failed to post to interface. &quot; + response.StatusCode;
          }
      }
  </code></pre>
  <p>changed to HttpClient:</p>
  <pre><code>        public static async Task&lt;string&gt; postToInterfaceNew(string linkExtension, string token = null, string JSON = null)
      {
          var body = new JObject();
          HttpClientHandler handler = new HttpClientHandler()
          {
  
          };
  
          using (HttpClient client = new HttpClient(handler))
          {
              client.BaseAddress = new Uri(&quot;https://owner-api.teslamotors.com/&quot;);
              client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(&quot;application/json&quot;));
              client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(&quot;Bearer&quot;, token); 
  
  
              using (var content = new StringContent(body.ToString(Newtonsoft.Json.Formatting.None), System.Text.Encoding.UTF8, &quot;application/json&quot;))
              {
                  HttpResponseMessage result = await client.PostAsync(client.BaseAddress + linkExtension, content).ConfigureAwait(false);
  
                  string resultContent = await result.Content.ReadAsStringAsync().ConfigureAwait(false);
  
                  return resultContent;
              }
          }
      }
  </code></pre>
  <p>Widget button:
  <a href="https://i.stack.imgur.com/xsiQo.jpg" rel="nofollow noreferrer">enter image description here</a></p>
  <p>App button:
  <a href="https://i.stack.imgur.com/hzXAb.jpg" rel="nofollow noreferrer">enter image description here</a></p>
  <p>I added an example that reproduces the issue at git:</p>
  <p><a href="https://github.com/salvesen/widgetSample" rel="nofollow noreferrer">https://github.com/salvesen/widgetSample</a></p>
  <p>Examples from the widgetSample where it falls on widget button but not app button:</p>
  <p><a href="https://i.stack.imgur.com/xsiQo.jpg" rel="nofollow noreferrer">enter image description here</a></p>
  <p><a href="https://i.stack.imgur.com/hzXAb.jpg" rel="nofollow noreferrer">enter image description here</a></p>