Skip to content

Instantly share code, notes, and snippets.

@yevrah
Created August 17, 2016 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yevrah/f3a77023e2acb7739d5b0292328eed34 to your computer and use it in GitHub Desktop.
Save yevrah/f3a77023e2acb7739d5b0292328eed34 to your computer and use it in GitHub Desktop.
CC: API Connection in CSharp
using System;
using System.IO;
using System.Net;
using System.Text; // for class Encoding
namespace ClassCover.Api.Example
{
public class API
{
public static void Main(string[] args)
{
var request = (HttpWebRequest)WebRequest.Create("http://app.classcover.com.au/api");
var postData = @"<?xml version='1.0' encoding='UTF-8'?><methodCall><methodName>system.listMethods</methodName> <params> </params> </methodCall>";
var data = Encoding.ASCII.GetBytes(postData);
request.Method = "POST";
request.ContentType = "text/xml";
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
Console.WriteLine(responseString);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment