I am using HttpClient to get http content from url. Some one provide me with example in php for service that i should use with username and password:
$user = "testUser";
$passwd = "testPassword";
$url = "testurl";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$user:$passwd");
$output = curl_exec($ch);
curl_close($ch);
echo $output;
How to convert that into c# code and provide it with username and password?
Now my code looks like this:
string url = "my url";
var result = string.Empty;
var client = new HttpClient();
var msg = await client.GetAsync(url);
if (msg.IsSuccessStatusCode)
{
var data = await msg.Content.ReadAsByteArrayAsync();
result = encoding.GetString(data);
}
Aucun commentaire:
Enregistrer un commentaire