We are developing a WP8 application that requires push notifications. To test it, we performed a POST request for push messages with the CURL command line, making sure that it actually connects, authenticates with the client's SSL certificate and sends the correct data. We know that this work, as we get, clicks on devices.
This is the CURL command that we used for testing:
curl --cert client_cert.pem -v -H "Content-Type:text/xml" -H "X-WindowsPhone-Target:Toast" -H "X-NotificationClass:2" -X POST -d "<?xml version='1.0' encoding='utf-8'?><wp:Notification xmlns:wp='WPNotification'><wp:Toast><wp:Text1>My title</wp:Text1><wp:Text2>My subtitle</wp:Text2></wp:Toast></wp:Notification>" https://db3.notify.live.net/unthrottledthirdparty/01.00/AAF9MBULkDV0Tpyj24I3bzE3AgAAAAADCQAAAAQUZm52OkE1OUZCRDkzM0MyREY1RkE
Of course, our SSL certificate is necessary for the actual use of the URL, but I was hoping that someone else would do this and could see what we were doing wrong.
Now our problem is that we need to do this work with Ruby instead, something we have not been able to refine with so far.
We tried using HTTParty with no luck, and also net / http directly with no luck.
Here is a very simple HTTParty script test that I used for testing:
require "httparty" payload = "<?xml version='1.0' encoding='utf-8'?><wp:Notification xmlns:wp='WPNotification'><wp:Toast><wp:Text1>My title</wp:Text1><wp:Text2>My subtitle</wp:Text2></wp:Toast></wp:Notification>" uri = "https://db3.notify.live.net/unthrottledthirdparty/01.00/AAF9MBULkDV0Tpyj24I3bzE3AgAAAAADCQAAAAQUZm52OkE1OUZCRDkzM0MyREY1RkE" opts = { body: payload, headers: { "Content-Type" => "text/xml", "X-WindowsPhone-Target" => "Toast", "X-NotificationClass" => "2" }, debug_output: $stderr, pem: File.read("/Users/kenny/Desktop/client_cert.pem"), ca_file: File.read('/usr/local/opt/curl-ca-bundle/share/ca-bundle.crt') } resp = HTTParty.post uri, opts puts resp.code
This seems like a valid SSL connection, but then the MS IIS server returns 403 to us for some reason that we donβt get.
Here is essentially the same thing I tried using net / http:
require "net/http" url = URI.parse "https://db3.notify.live.net/unthrottledthirdparty/01.00/AAF9MBULkDV0Tpyj24I3bzE3AgAAAAADCQAAAAQUZm52OkE1OUZCRDkzM0MyREY1RkE" payload = "<?xml version='1.0' encoding='utf-8'?><wp:Notification xmlns:wp='WPNotification'><wp:Toast><wp:Text1>My title</wp:Text1><wp:Text2>My subtitle</wp:Text2></wp:Toast></wp:Notification>" pem_path = "./client_cert.pem" cert = File.read pem_path http = Net::HTTP.new url.host, url.port http.use_ssl = true http.cert = OpenSSL::X509::Certificate.new cert http.key = OpenSSL::PKey::RSA.new cert http.ca_path = '/etc/ssl/certs' if File.exists?('/etc/ssl/certs') # Ubuntu http.ca_file = '/usr/local/opt/curl-ca-bundle/share/ca-bundle.crt' if File.exists?('/usr/local/opt/curl-ca-bundle/share/ca-bundle.crt') # Mac OS X http.verify_mode = OpenSSL::SSL::VERIFY_PEER r = Net::HTTP::Post.new url.path r.body = payload r.content_type = "text/xml" r["X-WindowsPhone-Target"] = "toast" r["X-NotificationClass"] = "2" http.start do resp = http.request r puts resp.code, resp.body end
Like the HTTParty version, this also returns 403 ..
I get the feeling that this actually does not work with net / http, but I also saw a few code examples that require work, but I do not see any difference compared to what we tested here.
Does anyone know how to fix this? Is it possible? Should I use libcurl instead, perhaps? Or even make a system call for curling? (I may have to make the latter as an interim solution if we cannot get it to work in the near future).
Any entry is welcome!
Thanks Kenny