Created
August 17, 2016 03:02
-
-
Save yevrah/f3a77023e2acb7739d5b0292328eed34 to your computer and use it in GitHub Desktop.
CC: API Connection in CSharp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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