Skip to content

Instantly share code, notes, and snippets.

@matsurigoto
Created June 30, 2019 15:41
using Newtonsoft.Json;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
namespace ConsoleApp1
{
class Program
{
public static string personalAccessToken = "your_personal_token";
public static string path = "/Test";
public class request
{
public string content { get; set; }
}
static void Main(string[] args)
{
using (var client = new HttpClient())
{
request req = new request { content = "New content for page" };
var jsonString = JsonConvert.SerializeObject(req);
var httpContent = new StringContent(jsonString, Encoding.UTF8, "application/json");
client.BaseAddress = new Uri("https://dev.azure.com");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(
System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", "", personalAccessToken))));
var response = client.PutAsync("/duranhsieh/Bupa Demo/_apis/wiki/wikis/TestDemo.wiki/pages?path=" + path + "&api-version=5.0", httpContent).Result;
if (response.IsSuccessStatusCode)
{
Console.WriteLine("Success");
}
else
{
Console.WriteLine("Error");
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment