Skip to content

Instantly share code, notes, and snippets.

@tankcdr
Created January 6, 2015 14:50
Show Gist options
  • Save tankcdr/f3071f65a92eff274256 to your computer and use it in GitHub Desktop.
Save tankcdr/f3071f65a92eff274256 to your computer and use it in GitHub Desktop.
AskQuestion-Making the call
public string AskQuestion(string question)
{
string answers = null;
string data = "{\"question\" : { \"evidenceRequest\":{\"profile\":\"NO\"},\"questionText\" : \"" + question + "\"}}";
var qaCall = (HttpWebRequest)WebRequest.Create(url);
try
{
string auth = string.Format("{0}:{1}", this.uid, this.pwd);
string auth64 = Convert.ToBase64String(Encoding.ASCII.GetBytes(auth));
string credentials = string.Format("{0} {1}", "Basic", auth64);
qaCall.Headers[HttpRequestHeader.Authorization] = credentials;
qaCall.Method = "POST";
qaCall.Accept = "application/json";
qaCall.ContentType = "application/json";
qaCall.Headers["X-SyncTimeOut"] = "30";
var encoding = new UTF8Encoding();
var payload = Encoding.GetEncoding("iso-8859-1").GetBytes(data);
qaCall.ContentLength = payload.Length;
using (var callStream = qaCall.GetRequestStream())
{
callStream.Write(payload, 0, payload.Length);
}
}
catch (Exception e)
{
Console.Out.WriteLine("error:" + e.Message);
Console.ReadKey();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment