Last active
April 15, 2019 17:52
-
-
Save saamerm/fb8a7695b8ffedc19d77d08639baa625 to your computer and use it in GitHub Desktop.
This gist helps in parsing String- "0" Responses that comes back from services in C3. Some annoying developers do not return REST services but instead return the response in a weird format of "0" which is an integer inside a string.
This file contains hidden or 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 static void Main(string[] args) | |
{ | |
var token = "{TOKEN GOES HERE}"; | |
// Method 1 of getting the string from the services | |
HttpClient client = new HttpClient(); | |
var uri = "https://q1.asdfsafasfa.com/IsMarriedAndConsent"; | |
var value = new AuthenticationHeaderValue(token); | |
client.DefaultRequestHeaders.Authorization = value; | |
string obstring = client.GetStringAsync(uri).Result; | |
Console.WriteLine(obstring); //"0" | |
// Method 2 of getting the string from the services | |
HttpClient client2 = new HttpClient | |
{ | |
BaseAddress = | |
new Uri("https://q1.asdfsafasfa.com/IsMarriedAndConsent/") | |
}; | |
client2.DefaultRequestHeaders.Add("Authorization", token); | |
var result = client2.GetStringAsync(""); | |
Console.WriteLine(result.Result); //"0" | |
int c; | |
Int32.TryParse(result.Result, out c); | |
var a = "0"; | |
var b = 0; | |
Console.WriteLine(a); //0 | |
Console.WriteLine(b); //0 | |
Console.WriteLine(c); //0 | |
bool x = c == 1 ? true : false; | |
Console.WriteLine(x); //false | |
// The output is | |
// "0" | |
// "0" | |
// 0 | |
// 0 | |
// 0 | |
// false | |
// Bonus, Getting the path of a URL without the base address | |
//var a = "https://asdfsafasfa/mobile/factsheets"; | |
//var b = "https://asdfsafasfa"; | |
//var c = a.Substring(b.Length); | |
//Console.WriteLine(b + c); // Test to make sure that a = b+c | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment