Created
January 6, 2015 14:50
-
-
Save tankcdr/f3071f65a92eff274256 to your computer and use it in GitHub Desktop.
AskQuestion-Making the call
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
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