Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9186441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:31:43+00:00 2026-06-17T19:31:43+00:00

I am new to accessing web services with Windows Phone 7/8. I’m using a

  • 0

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.

The php-page requires an authentication and I think that’s where my code is failing. Here’s my 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);
    }
}

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).

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?

Update: here’s what I can get out of the WebException (sorry for the bad formatting):

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.<>c_DisplayClasse.b_d(Object sendState)
at System.Net.Browser.AsyncHelper.<>c_DisplayClass1.b_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)

Update 2: Here’s the error log line:

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)”

401 I guess would suggest false credentials?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:31:44+00:00Added an answer on June 17, 2026 at 7:31 pm

    Okay, so I found a way to get this working. The problem was that the WebClient class couldn’t properly handle the cookies of the web service.

    After some Google searches I found this solution and it works perfectly:
    http://firebelly.net/post/3341374382/cookie-aware-webclient-for-wp7

    So basically you just make your own client class that extends the WebClient class which can store cookies.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When accessing Sphinx programmatically from PHP using SphinxAPI, the query command causes my web
From Windows 8 to Windows Server 2012 (IIS 8) with Web Management Services installed
I am using a java-based tool that includes jaxws-rt-2.1.4.jar for accessing web services. I
Sorry, but I'm new to accessing return from another domain. I have this url
new on ruby and using windows xp and rails 3, i want to send
I am getting Unauthorized error when accessing restful web services. My sample program looks
We have a very basic SOAP web service setup using Windows Authentication, open for
I'm switching my web services over from .ASMX to .SVC, however several of them
What are the best practices for accessing a WCF web service from an ASP.NET
I am accessing a web service using WCF. Using WSHttpBinding, Security mode is set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.