Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Request: add data to UrlLoader events even when they fail — Gideros Forum

Request: add data to UrlLoader events even when they fail

ndossndoss Guru
edited May 2012 in Suggestions & requests

The current UrlLoader behavior seems to be not to fill in event.data if the request fails. Some of the REST apis provide useful error messages when they fail (e.g., "invalid user id"). So .. would it be possible to fill in event.data on failed requests?

Comments

  • atilimatilim Maintainer
    Totally agree. Can someone post a simple PHP script that both provide data and HTTP error code at the same time?
  • JaviJavi Member
    edited May 2012
    HTTP responses (headers) and data are sent in the same stream; header + data.
    UrlLoader downloads (but ignores) the data if the header is not "200 OK".

    For example, test.php:
    <?php  
     
    //header("HTTP/1.0 404 Not Found"); 
    header("HTTP/1.0 200 OK"); // reply with "200 OK" or UrlLoader will ignore data
     
    echo("Data..." . "\0");
     
    flush(); 
    ?>
  • JaviJavi Member
    edited May 2012
    ... so, to solve this problem UrlLoader should *always* write in event.data the data sent by the server and the header in event.httpResponse (for example).

    BTW, to be able to use any protocol, if the first bytes received are not a standard HTTP response then event.httpResponse = nil and event.data = all_data_received
    (If the 5 first bytes received are not "HTTP/" then it's not the HTTP protocol).

    The format of the HTTP protocol is (response(header/s) + data):

    HTTP/[...][line_break] // header
    [...more headers...]
    [line_break] // extra line break (empty line) indicates the end of the HTTP response
    [now starts the data section until the end of the transfer]

    Note: line_break can be CRLF, CR or LF
Sign In or Register to comment.