Answers for "http authentication php ajax example"

2

jquery ajax basic authentication

var username="username_here";
var password="password_here";
$.ajax({
  type: "GET",
  url: "myapi.php",
  dataType: 'json',
  headers: {
    "Authorization": "Basic " + btoa(username + ":" + password)
  },
  success: function (result){
      console.log(result)
  }
});
Posted by: Guest on August-05-2019
0

http post request login example asp.net c#

using System;
using System.Text;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

namespace HttpClientAuth
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var userName = "user7";
            var passwd = "passwd";
            var url = "https://httpbin.org/basic-auth/user7/passwd";

            using var client = new HttpClient();

            var authToken = Encoding.ASCII.GetBytes($"{userName}:{passwd}");
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                    Convert.ToBase64String(authToken));

            var result = await client.GetAsync(url);

            var content = await result.Content.ReadAsStringAsync();
            Console.WriteLine(content);
        }
    }
}
Posted by: Guest on May-22-2020

Code answers related to "http authentication php ajax example"

Code answers related to "Javascript"

Browse Popular Code Answers by Language