title: Windows Phone - failing to get a string from a website with login information
body: <p>I am new to accessing web services with Windows Phone 7/8. I'm using a WebClient to get a string from a php-website. The site returns a JSON string but at the moment I'm just trying to put it into a TextBox as a normal string just to test if the connection works.</p>
  
  <p>The php-page requires an authentication and I think that's where my code is failing. Here's my code:</p>
  
  <pre><code>WebClient client = new WebClient();
  client.Credentials = new NetworkCredential("myUsername", "myPassword");
  client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
  client.DownloadStringAsync(new Uri("https://www.mywebsite.com/ba/php/jsonstuff.php"));
  
  void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
  {
      try
      {
          string data = e.Result;
          this.jsonText.Text = data;
      }
      catch (Exception ex)
      {
          System.Diagnostics.Debug.WriteLine(ex.Message);
      }
  }
  </code></pre>
  
  <p>This returns first a WebException and then a TargetInvocationException. If I replace the Uri with for example "http://www.google.com/index.html" the jsonText TextBox gets filled with html text from Google (oddly enough, this also works even when the WebClient credentials are still set). </p>
  
  <p>So is the problem in the setting of the credentials? I couldn't find any good results when searching for guides on how to access php-pages with credentials, only without them. Then I found a short mention somewhere to use the WebClient.Credentials property. But should it work some other way?</p>
  
  <p><strong>Update:</strong> here's what I can get out of the WebException (sorry for the bad formatting):</p>
  
  <p>System.Net.WebException: The remote server returned an error: NotFound.     --->System.Net.WebException: The remote server returned an error: NotFound.
     at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
     at System.Net.Browser.ClientHttpWebRequest.&lt;>c_<em>DisplayClasse.b</em>_d(Object sendState)
     at System.Net.Browser.AsyncHelper.&lt;>c_<em>DisplayClass1.b</em>_0(Object sendState)
     --- End of inner exception stack trace ---
     at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
     at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
     at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
     at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)</p>
  
  <p><strong>Update 2:</strong> Here's the error log line:</p>
  
  <p>Nov 16 17:51:12 myservice httpd[21036]: 127.0.0.1 - - [16/Nov/2012:17:51:12 +0200] "GET /ba/php/jsonstuff.php?origpath=/ba/php/jsonstuff.php HTTP/1.1" 401 290 "-" "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)"</p>
  
  <p>401 I guess would suggest false credentials?</p>