Persistent 404 Error Message on status request with token

Persistent 404 Error Message on status request with token

Postby seatvsd » Sat Jan 03, 2015 11:28 pm

Hello,

Has anyone used JavaScript to grab schedules with JSON API?

I have been successful in doing GET /20140530/version/mfdb-json proving that I can access the site from my application (SPA frontend for something I developing)..

I have also done POST /20140530/token to successfully retrieve a token from my application. [ {"response":"OK","code":0,"client":"mfdb-json","version":"0.25","serverID":"20140530.2","datetime":"2015-01-04T04:25:21Z"} ]

I know my account and token are valid, because I can use the token with Postman to get my account status . [{"code":0,"message":"OK","serverID":"20140530.1","token":"871dzzdkq1xxyy1416aff3e798046526"} ] (obviously, I have changed some chars in the token for posting here).

On invoking , GET /status, I get XMLHttpRequest cannot load https://json.schedulesdirect.org/20140530/status. Invalid HTTP status code 404 error.

However, when I try to get my account status from my application, I get 404 error, consistently... not sure why... below is the portion of the code that performs the request and process the response... any pointers to get this working will be much appreciated.

Here is what Postman and may application sends the server, the only difference being that my application doesn't send a postman-token :)

Request Header from my application:

Code: Select all
{
"host":"localhost:4000",
"connection":"keep-alive",
"cache-control":"no-cache",
"origin":"something",
"user-agent":"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36",
"token":"5355xxxxxxxxxxxxxxxxxxxxxxxxx360",
"accept":"*/*",
"accept-encoding":"gzip, deflate, sdch",
"accept-language":"en-US,en;q=0.8"
}



Request Header from POSTMan:
Code: Select all

{"host":"localhost:4000",
"connection":"keep-alive",
"cache-control":"no-cache",
"user-agent":"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36",
"token":"6xxxxxxxxxxdxxxxxxxxdxxxxxxxxx11",
"postman-token":"2331004d-81fd-6bf2-28f0-31091ed3409f",
"accept":"*/*",
"accept-encoding":"gzip, deflate, sdch",
"accept-language":"en-US,en;q=0.8",
"origin":"something"
}

____________________________Application Code Fragment_________________________

Code: Select all
function makeCORSRequest( method, url, data, callBack, errorFunction, accessToken  )
{
   var xhr = new XMLHttpRequest();
   xhr.open( method, url, true );
   xhr.dataType = 'json';
   
   xhr.onreadystatechange = function()
   {
      if( xhr.readyState == 4 )
      {
         if( xhr.status == 200 )
         {
            var response = JSON.parse(xhr.response);
            document.getElementById(constResponse).value = JSON.stringify(response);            
            if( callBack )
            {
               callBack(response);
            }
         }
      }
   };
   
   xhr.onerror = function()
   {
      document.getElementById(constResponse).value = JSON.stringify(xhr);            
      if( errorFunction )
      {
         errorFunction( xhr.response );
      }
   }
   
   if( accessToken )
   {      
      xhr.setRequestHeader( "token", accessToken );
      xhr.setRequestHeader( "Cache-Control", "no-cache" );
   }

   if(data)
   {
      var stringData = JSON.stringify(data);
      xhr.send(stringData);
   }else
   {
      xhr.send();
   }
}



function errorResponse( xhr )
{
   console.log( "Error Function was invoked during XMLHTTPRequest operation" );
}


function getAPIStatus(event)
{
   event.preventDefault;
   var url = inputs.sdUrl + constClient;
   makeCORSRequest( 'GET', url, null, function(response)
         {
            document.getElementById(constGetToken).disabled = false;      
         },  errorResponse, null );
}


function getToken(event)
{
   event.preventDefault();
   var data =    {
                username: inputs.username,
                password: inputs.pwdHash
            };
   var url = inputs.sdUrl + constToken;
   
   makeCORSRequest( 'POST', url, data, function(response)
            {
               inputs.token = response.token;      
               document.getElementById(constGetAccStatus).disabled = false;
            },  errorResponse );
}


function getAccStatus( event )
{
   event.preventDefault();
   var url = inputs.sdUrl + constStatus;
   var token = inputs.token;
   makeCORSRequest( 'GET', url, null, function(response){}, errorResponse, token );   
}

$("#getAPIStatus").click(getAPIStatus);
$("#getToken").click(getToken);
$("#getAccStatus").click(getAccStatus);
$("#getHeadends").click();
$("#getEPG").click();
$("#saveConfig").click();
$("#saveEPG").click();

Last edited by seatvsd on Sun Jan 04, 2015 5:37 pm, edited 1 time in total.
seatvsd
 
Posts: 2
Joined: Sat Jan 03, 2015 2:06 am

Re: Persistent 404 Error Message on status request with toke

Postby rkulagow » Sun Jan 04, 2015 11:47 am

I've checked the logs, and I can see the requests that you're making, but the 404's that you're getting must be coming from Amazon's load balancer, because they're not in the logs on the reverse proxy.

I think that this is all you based on timestamps:
Code: Select all
172.31.15.196 - - [04/Jan/2015:07:22:35 +0000] "GET /20140530/version/mfdb-json HTTP/1.1" 200 455 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"
172.31.15.196 - - [04/Jan/2015:07:22:38 +0000] "POST /20140530/token HTTP/1.1" 200 436 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"
172.31.15.196 - - [04/Jan/2015:07:22:48 +0000] "OPTIONS /20140530/headends?country=USA&postalcode=98116 HTTP/1.1" 404 805 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"


I'm not seeing a request to pull /status which means that the request wasn't correct before it even got to me.

A client which does work shows up like this in the logs:
172.31.36.177 - - [04/Jan/2015:07:23:17 +0000] "GET /20140530/status HTTP/1.1" 200 756 "-" "NextPVR (3.3.8)"

Also, "OPTIONS" isn't one of the methods that we use.

If you create a distinct user agent that will make it a little easier to pull your logs because I'll be able to search for it instead of just using timestamps.
rkulagow
SD Staff
 
Posts: 911
Joined: Tue Aug 14, 2007 3:15 pm

Re: Persistent 404 Error Message on status request with toke

Postby seatvsd » Sun Jan 04, 2015 5:34 pm

Robert,

I have send dome requests with user agent set to "SeaTVGrabber". Let me know what you find.

Not sure where the OPTIONS is coming from at all... here the code I use for both account status & Headends...

My requests, captured re-routing to local host looks like this:

Header for status:
Code: Select all
{"host":"localhost:4000","connection":"keep-alive","cache-control":"no-cache","origin":"http://evil.com/","user-agent":"SeaTVGrabber","token":"5355a5f715bb455a0a42f8bcc26df360","accept":"*/*","accept-encoding":"gzip, deflate, sdch","accept-language":"en-US,en;q=0.8"}


URL for status
Code: Select all
{"protocol":null,"slashes":null,"auth":null,"host":null,"port":null,"hostname":null,"hash":null,"search":null,"query":null,"pathname":"/status","path":"/status","href":"/status"}


Header for Headends:
Code: Select all
{"host":"localhost:4000","connection":"keep-alive","cache-control":"no-cache","origin":"http://evil.com/","user-agent":"SeaTVGrabber","token":"5355a5f715bb455a0a42f8bcc26df360","accept":"*/*","accept-encoding":"gzip, deflate, sdch","accept-language":"en-US,en;q=0.8"}


URL for Headends;
Code: Select all
{"protocol":null,"slashes":null,"auth":null,"host":null,"port":null,"hostname":null,"hash":null,"search":"?country=USA&postalcode=98116","query":"country=USA&postalcode=98116","pathname":"/headends","path":"/headends?country=USA&postalcode=98116","href":"/headends?country=USA&postalcode=98116"}



Here is the actual code that is making the calls:
Code: Select all
   const constSDUrl         = "https://json.schedulesdirect.org/20140530/";
//   const constSDUrl         = "http://localhost:4000/";
   const constClient        = "version/mfdb-json";
   const constToken         = "token";
   const constStatus        = "status";
   const constHeadends       = 'headends?country=';
function getAccStatus( event )
{
   event.preventDefault();
   var url = inputs.sdUrl + constStatus;
   makeCORSRequest( 'GET', url, null, function(response){}, errorResponse, inputs.token );   
}

function getHeadends( event )
{
   event.preventDefault();
   url = inputs.sdUrl + constHeadends + inputs.country + '&postalcode=' + inputs.postalCode;
   makeCORSRequest( 'GET', url, null, function(response){}, errorResponse, inputs.token );   
}



Thanks
GS
seatvsd
 
Posts: 2
Joined: Sat Jan 03, 2015 2:06 am


Return to Developer

Who is online

Users browsing this forum: No registered users and 10 guests

cron