1

Session Management Error in c#

Hi All,

i am sending the session request using c# here is my code

string URL_YM_SESSION = "http://developer.messenger.yahooapis.com/v1/session";

url = URL_YM_SESSION;
url = url + "?&oauth_consumer_key=xyz"; // adding the yahoo email address
url = url + "&oauth_signature_method=PLAINTEXT";
url = url + "&oauth_version=1.0";
url = url + "&oauth_token=" + marrAccessTokenAttribute[0].ToString();
url = url + "&oauth_timestamp=" + timestamp1;
url = url + "&oauth_nonce=" + new Random().Next(123400, 9999999).ToString(); // adding the password to the url
url = url + "&oauth_signature=abc123" + "%26" + marrAccessTokenAttribute[1].ToString();
url = url + "&notifyServerToken=1";

// creating the HTTP web request for the above created url
HttpWebRequest SignRequestToken = WebRequest.Create(url) as HttpWebRequest;

SignRequestToken.ContentType ="application/json; charset=utf-8";
SignRequestToken.Headers.Add(HttpRequestHeader.Authorization, marrAccessTokenAttribute[0].ToString());
SignRequestToken.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; EmbeddedWB 14.52 from: http://www.bsalsa.com/ EmbeddedWB 14.52; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 1.0.3705; .NET CLR 3.0.04506.30)";


StringBuilder sbPoststring = new StringBuilder();
sbPoststring.AppendLine("{");
sbPoststring.AppendLine("'presenceState' : 0 ,");
sbPoststring.AppendLine("'presenceMessage' : 'I am now logged in'");
sbPoststring.AppendLine("}");
string poststring = sbPoststring.ToString();

byte[] bytedata = Encoding.UTF8.GetBytes(poststring);
SignRequestToken.ContentLength = bytedata.Length;

SignRequestToken.Method = "post";

Stream stream;
using (stream = SignRequestToken.GetRequestStream())
{
stream.Write(bytedata, 0, bytedata.Length);
}


// getting the response
HttpWebResponse SignTokenResponse = SignRequestToken.GetResponse() as HttpWebResponse;
// getting the response string
StreamReader SignTokenResponseStream = new StreamReader(SignTokenResponse.GetResponseStream());

string SignTokenResponseString = SignTokenResponseStream.ReadToEnd();


i am getting this error

The remote server returned an error: (400) Bad Request.

with exception status as System.Net.WebExceptionStatus.ProtocolError

please let me know what is the issue with that.

thanks

by
2 Replies
  • Hi All,

    i have find out that if i comment these two lines in the post string then it works fine

    StringBuilder sbPoststring = new StringBuilder();
    sbPoststring.AppendLine("{");

    these two line......................
    //sbPoststring.AppendLine("'presenceState' : 0 ,");
    //sbPoststring.AppendLine("'presenceMessage' : 'I am now logged in'");

    sbPoststring.AppendLine("}");
    string poststring = sbPoststring.ToString();
    0
  • i got the right output just by reply the postdatastring with this code.


    StringBuilder sbPoststring = new StringBuilder();
    sbPoststring.AppendLine("{");
    sbPoststring.AppendLine("\"presenceState\" : 0,");
    sbPoststring.AppendLine("\"presenceMessage\" : \"I am now logged in\"");
    sbPoststring.AppendLine("}");

    cheers
    0

Recent Posts

in Messenger IM SDK