Skip to Content
avatar image
Former Member

HANA XS JS Failed to send request to socket

Hi,

I'm calling a web service from XS Engine in my HCP Trial Account, but I get a socket error as follows please help.

Erro Message:

HttpClient.request: request failed: internal error occurred "Failed to send request to socket...rc = -1"

HttpDest

host = "geocoder.cit.api.here.com";
port = 80;  
description = "HERE Geocoder";
useSSL = false;
pathPrefix = "/6.2/geocode.xml";
authType = none;
useProxy = false;
proxyHost = "proxy-trial";
proxyPort = 8080;
timeout = 3000;

XSJS File

var destination_package = "here";
var destination_name = "here";
var appid = "&<My App ID>";
var appcode = "&<my App Code>";
var gen = "≥n=8";
var address = "Walldorf Hasso-Plattner-Ring 7";
try {
	var dest = $.net.http.readDestination(destination_package, destination_name);
	var client = new $.net.http.Client();
	var req = new $.web.WebRequest($.net.http.GET, "?searchtext=" + address + appid + appcode + gen);
	client.request(req, dest);
	var response = client.getResponse();
	$.response.contentType = "application/json";
	$.response.setBody(response.body.asString());
	$.response.status = $.net.http.OK;
} catch (e) {
	$.response.contentType = "text/plain";
	$.response.setBody(e.message);
}
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Mar 15, 2017 at 07:33 PM

    There are different errors in your xshttpdest and the xsjs file.

    xshttpdest

    • As a "proxyHost" is set and must be used on the trial landscape, "useProxy" must be set to true instead of false.

    xsjs

    • You are just passing the app_id and app_code value, but not the parameter name. So it cannot be assigned. Also the gen parameter is not passed correctly.
    • Special signs in the URL have to be encoded (for instance the "-" in the address).
    • As the HERE geocoding API returns xml, you should set the content-type of your respone also the "application/xml" instead of "application/json".

    Following are the files for a working example (you just have to set the app_id and app_code values for your HERE project):

    host = "geocoder.cit.api.here.com1";
    port = 80;  
    description = "HERE Geocoder";
    useSSL = false;
    pathPrefix = "/6.2/geocode.xml";
    authType = none;
    useProxy = true;
    proxyHost = "proxy-trial";
    proxyPort = 8080;
    timeout = 3000;
    
    var destinationPackage = "here";
    var destinationName = "here";
    var appid = "<app_id value>";
    var appcode = "<app_code value>";
    var gen = "8";
    var address = encodeURI("Walldorf Hasso-Plattner-Ring 7");
    try {
    	var dest = $.net.http.readDestination(destinationPackage, destinationName);
    	var client = new $.net.http.Client();
    	var req = new $.net.http.Request($.net.http.GET, "?searchtext=" + address +
    	                                               "&app_id=" + appid + 
    	                                               "&app_code=" + appcode + 
    	                                               "&gen=" + gen);
    	
    	client.request(req, dest);
    	var response = client.getResponse();
    	$.response.contentType = "application/xml";
    	$.response.setBody(response.body.asString());
    	$.response.status = $.net.http.OK;
    	client.close();
    } catch (e) {
    	$.response.contentType = "text/plain";
    	$.response.setBody(e.message);
    }

    Regards,
    Florian

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hello Florian,

      Thank you for the quick Response.

      No all works fine.

      Thanks Klaus