sending an http request over ssh server

0

i have my data residing on an SSH server and i want to inquire and retrieve the data via HTTP POST and GET requests. i have been trying to do that using the simple url's http://127.0.0.1:9200/_search? but it gives me an empty response. What is the correct way to send requests over ssh server through http? my http post function looks something like this:

function spatialsearch(coordinates_selected) {
  var coords = coordinates_selected.geometry.coordinates;
  console.log('c',JSON.stringify(coordinates_selected.geometry.coordinates));
  var _url = 'http://127.0.0.1:9200/_search?';

  var b = {
    "query": {
      "bool": {
        "must": {
          "match_all": {}
        },
        "filter": {
          "geo_shape": {
            "metadata.o2r.spatial.geometry": {
              "shape": {
                "type": "polygon",
                "coordinates":
                coords

                /* [
                //     [-22.0, 76.0],
                //     [-27.0, 65.0],
                //     [-57.0, 65.0],
                //     [-59.0, 76.0],
                //     [-22.0, 76.0]
                ]*/

              },
              "relation": "within"
            }}}}}
  };

  console.log(b,'http sending request');
  return $http.post(_url,b);
}

i tried SSH tunneling using ssh -L9201:sshserver:9200 r_chau02@sshserver but i am still not getting any response.

update i updated the port in my code to 9201 but still the result was same. The error in console is net::ERR_EMPTY_RESPONSE while the terminal generates channel 3: open failed: connect failed: Connection refused.

Rehan

Posted 2017-05-17T08:22:47.247

Reputation: 3

This doesn't really sounds like it makes sense. SSH is SSH and HTTP is HTTP. I don't really get what you're trying to do. Do you have a webserver that would be able to answer the HTTP request? – Seth – 2017-05-17T08:35:18.863

@Seth i have webserver on which elasticsearch instance and all my data resides and which i access through SSH and now i have created an HTTP query to fetch that data but it's returning a bad request (400). The server is just a normal server. hope this clears out confusion – Rehan – 2017-05-17T08:45:09.490

Answers

0

You are looking in the right direction, with a minor error. The HTTP request and forwarding port don't match (9200 and 9201).

You can either update your code to query on port 9201, or change the ssh tunnel to:

ssh -L9201:127.0.0.1:9200 r_chau02@sshserver

This will make ES available on localhost:9200 (assuming tunneling is enabled on the server, and ES is listening on the sshserver address).

mtak

Posted 2017-05-17T08:22:47.247

Reputation: 11 805

i tried changing the port in code. it does not works. i have updated the question with some errors – Rehan – 2017-05-17T10:41:55.717

It seems your ES server is not listening on sshserver:9200. Is it bound to a specific IP? – mtak – 2017-05-17T12:10:04.867

i am just using the default configurations of ES and i think that by deafult it is bound to "127.0.0.1" although i am not sure. how should i make it listen? – Rehan – 2017-05-17T12:16:34.520

You don't have to. I updated my answer with an SSH tunnel that forwards from localhost:9201 on your client to 127.0.0.1:9200 on the remote host. – mtak – 2017-05-18T08:44:43.907

that worked fine but it would be great if i could access it without ssh tunnelling. i treid by changing me code to http:\\sshserver:9200. but i am recieving this error net::ERR_CONNECTION_REFUSED. – Rehan – 2017-05-18T10:56:34.753