private bool SetAgentCallback(int num_confirmations_required, string pingback_url)
{
m_log.Info("[FreeMoney] Telling the notification service to use the URL "+pingback_url);
string data = "req_confirmations="+num_confirmations_required.ToString()
+ "&url="+pingback_url;
//m_config["bitcoin_external_url"];
//string useragent = "Bitcoin payment module for OpenSim - https://github.com/edmundedgar/Mod-Bitcoin";
string url = m_config["bitcoin_ping_service_1_base_url"]+"/"+m_agent_id+"/"+"notification"+"/"+"url"+"/";
//Console.WriteLine(url);
//Console.WriteLine(data);
HttpWebRequest httpWebRequest=(HttpWebRequest)WebRequest.Create(url);
httpWebRequest.Headers.Add("Authorization: "+ m_config["bitcoin_ping_service_1_accesskey"]);
httpWebRequest.Method = "POST";
ASCIIEncoding encoding = new ASCIIEncoding ();
byte[] byte1 = encoding.GetBytes (data);
//httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.ContentLength = byte1.Length;
Stream newStream = httpWebRequest.GetRequestStream ();
newStream.Write (byte1, 0, byte1.Length);
newStream.Close();
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse ();
string response;
using (StreamReader streamReader = new StreamReader (httpWebResponse.GetResponseStream ())) {
response = streamReader.ReadToEnd ();
streamReader.Close ();
}
//Console.WriteLine(response);
if (httpWebResponse.StatusCode != HttpStatusCode.OK) {
m_log.Warn("[FreeMoney] Got a bad status code from the notification service when trying to set a callback URL.");
return false;
}
try {
JObject agent = (JObject)JObject.Parse(response);
if ( (int)agent["id"] != 0 ) {
// This is the URL id, but seeing "id" should mean we're ok
//m_agent_id = agent["id"].ToString();
return true;
}
} catch (Exception e) {
m_log.Warn("[FreeMoney] Could not understand the response when trying to set a callback URL.");
//m_log.Warn(Console.WriteLine(e.ToString());
//Console.WriteLine(response);
}
return false;
}