Question

I'm using httpsync for synchronous http requests. The server is written with django. I simply return false as response to a simple POST request:

HttpResponse(content="false", content_type="text/plain", status=200)

The request is:

function requiresDR(marker_type){
    var url = "http://" + config.adminpan.ip + ":" + config.adminpan.port  + config.adminpan.routes.is_marker_dr_required;
    var http_options = {
        'url': url,
        'method': 'POST'
    };
    var httpreq = httpsync.request(http_options);
    httpreq.write(marker_type);
    console.log(httpreq.end());
}

And the response is:

http://192.168.1.62:8000/adminpan/imdrr/
{ statusCode: 200,
  ip: '192.168.1.62',
  headers: 
   { date: 'Mon, 05 May 2014 01:30:16 GMT',
     server: 'WSGIServer/0.1 Python/2.7.3',
     'x-frame-options': 'SAMEORIGIN',
     'content-type': 'text/plain' },
  data: <SlowBuffer 64 61 74 61> }

The whole thing works perfectly with command line curl. So I assume the problem is not with the server, it is in the client-side.

Any ideas about how can I get data from the response using httpsync? Any ideas about the library itself or any other libraries are appreciated.

Was it helpful?

Solution

The data is coming back as a Buffer, not a string. The documentation for that can be found here. You can use data.toString() to get a more readable representation of it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top