You should put OAuth token in the url parameter, and set content-type to application/json; charset=utf-8
Here is the sample code:
CODE
Random random = new Random();
Hashtable access = (Hashtable) _token["access"];
string url = "http://developer.messenger.yahooapis.com/v1/session" +
"?oauth_consumer_key=" + _config["consumer_key"] +
"&oauth_nonce=" + random.Next(10000000, 99999999) +
"&oauth_signature=" + _config["secret_key"] + "%26" + access["oauth_token_secret"] +
"&oauth_signature_method=PLAINTEXT" +
"&oauth_timestamp=" + getTimestamp() +
"&oauth_token=" + access["oauth_token"] +
"&oauth_version=1.0" +
"¬ifyServerToken=1";
string postdata = "{\"presenceState\" : " + state + ", \"presenceMessage\" : \"" + status + "\"}";
string rs = fetchURL(url, true, postdata);
CODE
public string fetchURL(string url, bool json, string postData)
{
_error = "";
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[8192];
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
if (json)
{
request.ContentType = "application/json; charset=utf-8";
}
if (postData != "")
{
request.Method = "POST";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(postData);
request.ContentLength = data.Length;
Stream newStream = request.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
string tempString = null;
int count = 0;
do
{
count = resStream.Read(buf, 0, buf.Length);
if (count != 0)
{
tempString = Encoding.ASCII.GetString(buf, 0, count);
sb.Append(tempString);
}
}
while (count > 0);
}
catch (WebException e)
{
_error = e.Message;
return "";
}
return sb.ToString();
}
private string getTimestamp()
{
double t = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
return t.ToString();
}
Thx
~jimmi