0
我正在用C#編寫代碼來構建控制檯來實現獲取請求。 我們使用POSTMAN來完成任務,但我們決定建立自己的。C#中的授權標頭和內容類型#
我需要在請求的標題中傳遞用戶名和密碼。 由於我是編程新手,你能指導我嗎?
我已經寫了下面的代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
namespace ConsoleApp2
{
class Program
{
private static object response;
static void Main(string[] args)
{
GetRequest("https://www.google.com");
Console.ReadKey();
}
async static void GetRequest(string url)
{
using (HttpClient client = new HttpClient())
{
using (HttpResponseMessage response = await client.GetAsync(url))
{
using (HttpContent content = response.Content)
{
string mycontent = await content.ReadAsStringAsync();
Console.WriteLine(mycontent);
}
}
}
}
}
}
是什麼網址...它在郵遞員上工作..你在哪裏設置頭和應用程序類型在HttpClient? –
如果你花時間尋找答案而不是要求答案,那將會很棒。 –