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


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!

Recommended Answers

All 3 Replies

You can use IndexOf:

String myString = (new StreamReader(response.GetResponseStream()).ReadToEnd();

int n = myString.IndexOf("Auth=");
if (n >= 0) {  // Make sure we found it at all
    String token = myString.SubString(n+5); // +5 to skip the "Auth="
    ... process token

Thanx! That'll do.. but I was thinking if this can be done using RegEx.. I hear that thats much quicker and efficient..

If someone told you it was quicker and efficient, don't ever trust them again. Regex is an expensive process.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.