0

I am using WinRT framework. I have to get JSON response from service URL by passing username and password.

Here is the code I have tried

var credentials = new NetworkCredential("***", "***");
        var handler = new HttpClientHandler { Credentials = credentials };
        //client.DefaultRequestHeaders.Add("UserID", "****");
        //client.DefaultRequestHeaders.Add("Password", "****");
        HttpClient client = new HttpClient(handler);

But this throw error

Response status code does not indicate success: 500 (Internal Server Error).

Any help is appreciated.

4

1 回答 1

1

你唯一想念的是User-Agent。这有效....

var credentials = new NetworkCredential("****", "*****");
var handler = new HttpClientHandler { Credentials = credentials, AllowAutoRedirect = true };

HttpClient client = new HttpClient(handler);
client.DefaultRequestHeaders.Add("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12"); 
var responseString = await client.GetStringAsync("https://mobility.gap.com/MobileAppProvider/resources/gapresources/v1/buildings");
于 2013-04-24T06:26:24.387 回答