Search code examples
c#google-docs-api

Parsing token in HTTP Response body using C#


I'm sending an HTTP POST request to google Client login and I'm getting this in respons:

SID=DQAAAGgA...7Zg8CTN
LSID=DQAAAGsA...lk8BBbG
Auth=DQAAAGgA...dk3fA5N

I used the below code to read the response:

Trace.WriteLine(new StreamReader(response.GetResponseStream()).ReadToEnd());

Now in this response i want to use only the value of Auth token. Can any one please help me on how to extract only that value from the response. Thanx!


Solution

  • Just a quick answer, what you need to write could be something similar to this piece of code:

    String.Split("\n").Where(l=>l.Contains("=")).Select(l=l.Split("=")).Where(li=>li.Length==2).Where(li=>li[0].ToLower()=="auth").Select(li=>li[1]).SingleOrDefault();