How to make HTTPS requests with serverside javascript using Worklight?

后端 未结 2 1423
逝去的感伤
逝去的感伤 2021-01-05 01:36

I\'m toying around with IBM worklight, and am trying to create an adapter to feed some data in from the Google places API.

I want to call this URL :

         


        
2条回答
  •  余生分开走
    2021-01-05 01:49

    Looks like googleapis will not work if you don't specify Host header inside of your request. After adding it everything works as it should:

    This is adapters's XML section

    
        
            https
            maps.googleapis.com
            443            
        
        
    
    

    This is adapter's JS:

    function doGet() {
    
    var input = {
        method : 'get',
        returnedContentType : 'json',
        path : 'maps/api/place/search/json',
        headers: {
            Host: 'maps.googleapis.com'
        },
        parameters : {
            'key'       :   'AIzaSyCTlPms1pvhzeoRrBao5qW-DJMI_CWcbAM',
            'location'  :   '52.0700,1.1400',
            'radius'    :   '10000',
            'sensor'    :   'false',
            'name'      :   'coffee' 
        }
    };
    
    var response = WL.Server.invokeHttp(input);
    return response;
    

    }

提交回复
热议问题