Stiamo sviluppando un'applicazione WP8 che richiede notifiche push. Per testarlo abbiamo eseguito la richiesta POST di notifica push con la riga di comando CURL, assicurandoci che si connetta effettivamente, autentifichi con il certificato SSL del client e invii i dati corretti. Sappiamo per certo che questo lavoro come stiamo ricevendo spinge ai dispositivi.Connessione a Microsoft Push Notification Service per Windows Phone 8 da Ruby
Questo è il comando CURL abbiamo usato a scopo di test:
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
Naturalmente è necessaria la nostra CERT dello SSL utilizzare effettivamente l'URL, ma speravo che qualcun altro ha fatto questo e può vedere ciò che stiamo sbagliando.
Ora, il nostro problema è che dobbiamo invece lavorare con Ruby, qualcosa che non siamo riusciti a portare a termine finora.
Abbiamo provato a utilizzare HTTParty senza fortuna e anche net/http direttamente senza fortuna.
Ecco uno script di test HTTParty molto semplice che ho usato per testare con:
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
Questo sembra connettersi con SSL correttamente, ma poi il server MS IIS restituisce 403 a noi per qualche ragione noi don' ottenere.
Qui è essenzialmente la stessa cosa che ho provato ad utilizzare 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
Come la versione HTTParty, restituisce anche 403 ..
sto iniziando ad avere la sensazione che questo in realtà non funzionerà con net/http, ma ho anche visto alcuni esempi di codice che pretendono di funzionare, ma non vedo differenze rispetto a ciò che abbiamo testato qui.
Qualcuno sa come risolvere questo problema? È possibile? Dovrei usare libcurl invece, forse? O anche fare una chiamata di sistema per arricciare? (Potrei dover fare l'ultimo come soluzione provvisoria se non riusciamo a farlo funzionare presto).
Qualsiasi input è molto apprezzato!
Grazie, Kenny
Qualche progresso sulla vostra parte? Ho provato da Node.js con codice simile e sono rimasto bloccato. Vorrei poter vedere un registro degli errori nell'area Dev Center per i certificati o qualcosa che aiuti a diagnosticare quale potrebbe essere il problema. –
Ci scusiamo per la risposta in ritardo, ma no, non ho potuto farlo funzionare. Abbiamo dovuto ricorrere a chiamare in CURL per ora .. –