- 
            
      
        
      
    Star
      
          
          (131)
      
  
You must be signed in to star a gist 
- 
              
      
        
      
    Fork
      
          
          (43)
      
  
You must be signed in to fork a gist 
- 
      
- 
        Save bryanbarnard/8102915 to your computer and use it in GitHub Desktop. 
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using System.Net.Http; | |
| using System.Net; | |
| namespace HTTP_Test | |
| { | |
| class program | |
| { | |
| static void Main() | |
| { | |
| Task t = new Task(HTTP_GET); | |
| t.Start(); | |
| Console.ReadLine(); | |
| } | |
| static async void HTTP_GET() | |
| { | |
| var TARGETURL = "http://en.wikipedia.org/"; | |
| HttpClientHandler handler = new HttpClientHandler() | |
| { | |
| Proxy = new WebProxy("http://127.0.0.1:8888"), | |
| UseProxy = true, | |
| }; | |
| Console.WriteLine("GET: + " + TARGETURL); | |
| // ... Use HttpClient. | |
| HttpClient client = new HttpClient(handler); | |
| var byteArray = Encoding.ASCII.GetBytes("username:password1234"); | |
| client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); | |
| HttpResponseMessage response = await client.GetAsync(TARGETURL); | |
| HttpContent content = response.Content; | |
| // ... Check Status Code | |
| Console.WriteLine("Response StatusCode: " + (int)response.StatusCode); | |
| // ... Read the string. | |
| string result = await content.ReadAsStringAsync(); | |
| // ... Display the result. | |
| if (result != null && | |
| result.Length >= 50) | |
| { | |
| Console.WriteLine(result.Substring(0, 50) + "..."); | |
| } | |
| } | |
| } | |
| } | 
thankkk youuuu
It took me a while to find out how to encode the username and password into the authorization header, your code saved me a lot of trouble, thanks!
thanks!
Great Work?
Can you guide me
How to handle below json format using C# (with Authentication) - Post Method with Body(Raw)
{
"CustomerCode": "F101",
"CusReferenceNo": "3",
"StationName": "fsa",
"SalesmanId": "5",
"OrderStatus": "CLS",
"PostingDate": "2021-01-07",
"orderDetails":[
    {
"ItemCode": "100-0001-00002",
"Quantity": "25000.000000",
}]
}
Appreciated, if you guide me and share sample code
Getting trouble with downloading the PFD files from the webpage ("https://www.*******.com/produ/abc.pdf) with user authentication through using C# "HttpClient"
The webpage having some Cookies also
i followed the same as your code.
Please guide me how download through code (C#)?
Getting trouble with downloading the PFD files from the webpage ("https://www.*******.com/produ/abc.pdf) with user authentication through using C# "HttpClient"
The webpage having some Cookies also
i followed the same as your code.
Thank you!
Thank you very much, you saved my day