通过Azure发送HTTP请求

时间:2013-01-31 03:11:01

标签: javascript http azure xmlhttprequest azure-storage

我正在尝试通过他们的广播API与Urbanairship进行互动,以便在INSERT上向Android设备发送通知到Azure表中。

Azure上的JavaScript INSERT代码如下:

    function insert(item, user, request) {

        request.execute({
            success: function() {
                request.respond(statusCodes.OK, item.id);
                push();
            }
        });
    }

    function push() {
   var client = new XMLHttpRequest();
    var authen = 'UDQ3N...B'
    var url = "https://go.urbanairship.com/api/push/broadcast/";
    var data = '{ "android": { "alert": "Hello from Azure!"} }';

    client.open("POST", url, true);
    client.setRequestHeader('Authorization','Basic ' + authen); 
    client.setRequestHeader('Content-Type', 'application/json');
    client.setRequestHeader('Content-Length', '54');
    client.send(data);
}

但是我没有收到Urbanairship的回复。我确信它是Azure的一个问题,因为使用fiddler可以使用以下HTTP请求:

POST https://go.urbanairship.com/api/push/broadcast/ HTTP/1.1
User-Agent: Fiddler
Authorization: Basic UDQ3N...B
Content-Type: application/json
Host: go.urbanairship.com
Content-Length: 54

{ "android": { "alert": "Hello from Urban Airship!"} }

所以从本质上讲,我试图通过Azure用JavaScript重复这个调用,但没有运气。有什么建议吗?

1 个答案:

答案 0 :(得分:3)