How to make HTTPS requests with serverside javascript using Worklight?

后端 未结 2 1342
逝去的感伤
逝去的感伤 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

    <connectivity>
        <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
            <protocol>https</protocol>
            <domain>maps.googleapis.com</domain>
            <port>443</port>            
        </connectionPolicy>
        <loadConstraints maxConcurrentConnectionsPerNode="2" />
    </connectivity>
    

    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;
    

    }

    0 讨论(0)
  • 2021-01-05 01:50

    in your adapter there is also an {ADAPTER NAME}.xml

    In it, under connectivity under connectionPolicy, there is the protocol. did you change it to https and deploy?

    0 讨论(0)
提交回复
热议问题