Using makeWebRequest to retreive plain text data

Former Member
Former Member
Hi

I already use makeWebRequest to get json data but have to use it to retreive plain text data. I wrote the following code

function loadTextFromUrl( url )
{
var params = {
};

var headers = {
// body will be encoded as 'a=1&b=2'
"Content-Type" => Comm.REQUEST_CONTENT_TYPE_URL_ENCODED
};

var options = {
:method => Comm.HTTP_REQUEST_METHOD_GET,
:headers => headers,
:responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_URL_ENCODED
};

Comm.makeWebRequest(
url,
params,
options,
method(:onReceive)
);
}


the call to makeWebRequest is OK but I get a -400 error (INVALID_HTTP_BODY_IN_NETWORK_RESPONSE). I guess the system tries to decode the received data but I just need to get plain text data.

Is it possible ? How should I call makeWebRequest then ?

Thx
  • I've never heard of any way to get plain text with makeWebRequest. Json data (which gets converted into a dictionary), an image, a .fit, or .gpx - that's about it.
  • Former Member
    Former Member over 7 years ago
    Thanks...
  • Former Member
    Former Member over 7 years ago
    There is already a ticket open to add support for plain text responses. I've added a link to this thread to the ticket in hopes that more demand can get things moving along. Unfortunately changes like this require several teams to get involved which does take more time.
  • While we're at it, binary with a returned MIME type would be good too.

    Obviously the key issue is the internal representation in CIQ. There's no concept of a Binary Buffer that can be read as a byte or Unicode stream.

    That said, I'd be very happy with text/plain.
  • Former Member
    Former Member over 7 years ago
    Ya, I'm not sure how that data would be presented in the callback; that may require a language change. The plain text seems (to me at least) that it would be a slam dunk as you simply would have to copy the body into a string and pass it along.
  • There is already a ticket open to add support for plain text responses. I've added a link to this thread to the ticket in hopes that more demand can get things moving along. Unfortunately changes like this require several teams to get involved which does take more time.


    has there been any movement on this? i now also need a plain text response (to get a simple string login token from a server that is not under my control). is there any hope for this or should i give up?
  • The a look at CIQ beta 3.0, this has a couple of new types, one of which is HTTP_RESPONSE_CONTENT_TYPE_TEXT_PLAIN. So you should not have to wait much longer.
  • The a look at CIQ beta 3.0, this has a couple of new types, one of which is HTTP_RESPONSE_CONTENT_TYPE_TEXT_PLAIN. So you should not have to wait much longer.


    very cool - thanks. but ,i just tried the 3.0.0 beta 2 sdk and although its accepting the text_plain enum, it still fails on a text response.

    function onReceiveTestLogin(responseCode, data) {
    myPrintLn("in onReceiveTestLogin, responseCode=" + responseCode + ", data=" + data);
    }
    ...
    Communications.makeWebRequest("tynbendad.github.io/.../response-login",
    {}, { :method => Communications.HTTP_REQUEST_METHOD_GET,
    :headers => { // set headers
    "Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED},
    :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_TEXT_PLAIN
    }, method(:onReceiveTestLogin));
    ...


    >in onReceiveTestLogin, responseCode=-400, data=null

    maybe its not quite ready yet?
  • Horsetooth,

    I'm using your code here in the sim with the 3.0.0.beta2 SDK and i"m getting what looks to be a store id for an app. Is this correct. If you want I can post my output. I'm not sure why that's returning null for you..

    - Coleman
  • Horsetooth,

    I'm using your code here in the sim with the 3.0.0.beta2 SDK and i"m getting what looks to be a store id for an app. Is this correct. If you want I can post my output. I'm not sure why that's returning null for you..

    - Coleman


    thanks Coleman - so you didn't get -400 responseCode? i'm still getting that here, i may have to reinstall a fresh eclipse/sdk. can you post a .zip of the test project that worked for you?