http 304 error

Nov 10, 2011 at 7:05 PM

Hi,

Please help...

while consuming a SAP odata service i am getting  Http 304 error

‎‎/Scripts/datajs-1.0.2.min.js GET 304 application/x-javascript 176 B < 1 ms <script> 187 0 0 0 0 84

 

regards

Saurabh

Nov 12, 2011 at 2:33 AM

Hi Saurabh,

   Hope you are doing great.  Http 304 status code means "not modified" and it is usually received from the server if your request includes a "If-Modified-Since" header in the request.  Is this the case?  Can you provide a trace of the http request?

Thanks,

Alex Trigo. 

Nov 12, 2011 at 5:15 PM
Hi ATrigo

I am trying to consume a Odata service using Datajs :-

http://gw.esworkplace.sap.com/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/FlightCollection

User: GW@ESW

Password: ESW4GW

It works on normal call using browser but Datajs sample code is not able to connect to gateway. I am attaching my sample html code for your reference.

Regards

Saurabh

--------------------------------------------------------

On Sat, Nov 12, 2011 at 8:03 AM, ATrigo <notifications@codeplex.com> wrote:

From: ATrigo

Hi Saurabh,

Hope you are doing great. Http 304 status code means "not modified" and it is usually received from the server if your request includes a "If-Modified-Since" header in the request. Is this the case? Can you provide a trace of the http request?

Thanks,

Alex Trigo.

Read the full discussion online.

To add a post to this discussion, reply to this email (datajs@discussions.codeplex.com)

To start a new discussion for this project, email datajs@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Nov 12, 2011 at 9:30 PM
Edited Nov 12, 2011 at 9:31 PM

 

<!DOCTYPE html>
<html>
<head>
<title>hello world</title>
    <script src="Scripts/datajs-1.0.2.js" type="text/javascript"></script>

    
</head>

<body>
    
    <div id="results"></div>

<script type="text/javascript">

    // Root URI for the service.
    OData.defaultHttpClient.enableJsonpCallback = false;
    var serviceUri = "https://gw.esworkplace.sap.com/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/";

    function getFlightList() {

        var cityFrom = "frankfurt";
        var cityTo = "NEW YORK";
        var fromDate = "19950221";
        var toDate = "19950228";
        var myEndpointUri="FlightCollection(carrid='LH',connid='0400',fldate='19950228')";
        var myEndpointUri = serviceUri + "GetAvailableFlights?cityfrom=" + cityFrom + "&cityto=" + cityTo + "&fromdate=" + fromDate + "&todate=" + toDate;



        OData.read(myEndpointUri, function (data) {

               var html = "";
               for (var i = 0; i < data.results.length; i++) {
                   html += "<div>" + "Flight Carrier: " + data.results[i].carrid + "<br/></div>";
                   html += "<div>" + "Flight Price: " + data.results[i].PRICE + "<br/></div>";
                   html += "<div>" + "Flight Max. Seats:" + data.results[i].SEATSMAX + "<br/><br/></div>";

               }

               document.getElementById("results").innerHTML = html;

           },
          function (err) {
              //Error Callback:

              alert("Error occurred " + err.message);
          }
            ) ;
      }
    
</script>

</body>
</html>

Nov 14, 2011 at 8:24 PM

Hi Saurabh,

Hope you are doing great.  Thanks for the code..  I think that the problem you are facing is that you are not passing the user and password to the request. Your OData endpoint is secured and you need to use user name and password for it to work:

OData.read({ requestUri: myEndpointUri, user:"user", password:"password" },  function (data) {

               var html = "";
               for (var i = 0; i < data.results.length; i++) {
                   html += "<div>" + "Flight Carrier: " + data.results[i].carrid + "<br/></div>";
                   html += "<div>" + "Flight Price: " + data.results[i].PRICE + "<br/></div>";
                   html += "<div>" + "Flight Max. Seats:" + data.results[i].SEATSMAX + "<br/><br/></div>";

               }

               document.getElementById("results").innerHTML = html;

           },
          function (err) {
              //Error Callback:

              alert("Error occurred " + err.message);
          }
            ) ;

Regards,

Alex Trigo.

Nov 15, 2011 at 9:02 AM
Hi Atrigo,

Thanks for your reply but this still doesn't work.I am attaching the HTTP log:-



Key Value
Accept application/javascript, */*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-US
Connection Keep-Alive
Host localhost:50966
If-None-Match "1CC9A075A757F00"
Request GET /Scripts/datajs-1.0.2.js HTTP/1.1
User-Agent Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)

Key Value
Response HTTP/1.1 304 Not Modified
X-AspNet-Version 4.0.30319
ETag " 1CC9A075A757F00"
Content-Type application/x-javascript
Content-Length 314266
Expires Wed, 16 Nov 2011 08:50:14 GMT


HTML CODE :-

<html>
<head>
<title>hello world</title>
</head>

<body>

<script type="text/javascript">

// Root URI for the service.
// OData.defaultHttpClient.enableJsonpCallback = false;

function getFlightList() {

var cityFrom = "frankfurt";
var cityTo = "NEW YORK";
var fromDate = "19950221";
var toDate = "19950228";
// var myEndpointUri="FlightCollection(carrid='LH',connid='0400',fldate='19950228')";
var myEndpointUri = serviceUri + "GetAvailableFlights?cityfrom=" + cityFrom + "&cityto=" + cityTo + "&fromdate=" + fromDate + "&todate=" + toDate;



OData.read({ requestUri: myEndpointUri,user:"S0007475475",password:"h4Qb706e"}, function (data) {
// OData.read(myEndpointUri, function (data) {

var html = "";
for (var i = 0; i < data.results.length; i++) {
html += "
" + "Flight Carrier: " + data.results[i].carrid + "
";
html += "
" + "Flight Price: " + data.results[i].PRICE + "
";
html += "
" + "Flight Max. Seats:" + data.results[i].SEATSMAX + "

";

}

document.getElementById("results").innerHTML = html;

},
function (err) {
//Error Callback:

alert("Error occurred " + err.message);
}
) ;
}
</script>

</body>
</html>








I think since this is cross domain java script call i.e. Odata service is hosted
@ http://gw.esworkplace.sap.com:80 but i m consuming this in my .NET 2011 HTML5 project running @ my machine's LOCALHOST.

I will be waiting for your reply.
Thanks tc cr :)

regards
Saurabh





On Tue, Nov 15, 2011 at 1:54 AM, ATrigo <notifications@codeplex.com> wrote:

From: ATrigo

Hi Saurabh,

Hope you are doing great. Thanks for the code.. I think that the problem you are facing is that you are not passing the user and password to the request. Your OData endpoint is secured and you need to use user name and password for it to work:

OData.read({ requestUri: myEndpointUri, user:"user", password:"password" }, function (data) {

var html = "";
for (var i = 0; i < data.results.length; i++) {
html += "

" + "Flight Carrier: " + data.results[i].carrid + "
";
html += "
" + "Flight Price: " + data.results[i].PRICE + "
"
;
html += "
" + "Flight Max. Seats:" + data.results[i].SEATSMAX + "

"
;

}

document.getElementById("results").innerHTML = html;

},
function (err) {
//Error Callback:

alert("Error occurred " + err.message);
}
) ;

Regards,

Alex Trigo.

Read the full discussion online.

To add a post to this discussion, reply to this email (datajs@discussions.codeplex.com)

To start a new discussion for this project, email datajs@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Nov 15, 2011 at 6:20 PM
Edited Nov 15, 2011 at 6:34 PM

Hi Saurabh,

   How are you determining that this is an error? Does the error handler of OData.read() is firing up and you see a message box with an error message? Or you are looking at the network capture and seeing this particular request that returned a 304 status code?   I ask you this because, the request / response you mention is the one that the browser made to download the library and the server's response is that it hasn't been modified so the browser can use the copy of datajs-1.0.2.js that it has in the cache:

Key Value
Accept application/javascript, */*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-US
Connection Keep-Alive
Host localhost:50966
If-None-Match "1CC9A075A757F00"
Request GET /Scripts/datajs-1.0.2.js HTTP/1.1
User-Agent Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
Key Value
Response HTTP/1.1 304 Not Modified
X-AspNet-Version 4.0.30319
ETag " 1CC9A075A757F00"
Content-Type application/x-javascript
Content-Length 314266
Expires Wed, 16 Nov 2011 08:50:14 GMT

The only issue i noticed with your code was the lack of user and password when calling OData.read()

Regards,

Alex Trigo.

Nov 17, 2011 at 5:56 PM

Hi Alex,

 

Ya i  understand that part but after adding credentials still its not showing anything , i running it from vs 2010 MVC project, When i debug using .NET after this line

 

<html>
<head>

     <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script src="Scripts/datajs-1.0.2.js" type="text/javascript"></script>
    
      <script type="text/javascript">
          google.load("jquery", "1"); // 1.5.2
    </script>

    
  

<script type="text/javascript">

    // Root URI for the service.

    var serviceUri = "http://gw.esworkplace.sap.com:80/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/";

    function getFlightList() {

        var cityFrom = "frankfurt";
        var cityTo = "NEW YORK";
        var fromDate = "19950221";
        var toDate = "19950228";

        var myEndpointUri = serviceUri + "GetAvailableFlights?cityfrom=" + cityFrom + "&cityto=" + cityTo + "&fromdate=" + fromDate + "&todate=" + toDate;



         OData.read({ requestUri: myEndpointUri,user:"S0007475475",password:"h4Qb706e"}, function (data) {
       // OData.read(myEndpointUri, function (data) {

               var html = "";
               for (var i = 0; i < data.results.length; i++) {
                   html += "<div>" + "Flight Carrier: " + data.results[i].carrid + "<br/></div>";
                   html += "<div>" + "Flight Price: " + data.results[i].PRICE + "<br/></div>";
                   html += "<div>" + "Flight Max. Seats:" + data.results[i].SEATSMAX + "<br/><br/></div>";

               }

               document.getElementById("results").innerHTML = html;

           },
          function (err) {
              //Error Callback:

              alert("Error occurred " + err.message);
          }
            ) ;
      }
    
</script>
</head>
<title>dd</title>
<body>

  <div id="results"></div>
   
</body>
</html>

i don't get any breakpoints , so i think its not initiating after calling the above line, can you please try running my code

 

regrads

saurabh

Jan 4, 2012 at 12:07 PM

hi,

i also was trying to get some data from sap netweaver gatewat demo system but unfortunately, i was not able.

i have been playing around with the codes you have been posting, but there is no way to get this run well.

have you got any other clues to get this work?

thanks in advance for your help.

acos rodriguez

Jan 4, 2012 at 3:15 PM

Finally it worked... here is the code.

Remember to change the user and password with your credentials.

And the most important thing, in my case, it only worked with IE, i tried on firefox and chrome and it did not work.

 

<!DOCTYPE html>
<html>
<head>
<title>test</title>
  <script src="http://domain.netau.net/datajs-1.0.2.js" type="text/javascript"></script> 
</head>

<body onload="getData()">
    <div id="results"><h3>Call gateway service</h3></div>

<script type="text/javascript">
    function getData() {
      var serviceUri = "http://gw.esworkplace.sap.com/sap/opu/sdata/iwfnd/catalogservice/CatalogCollection%28ID%3d%27HW1%27%29/Services";
      OData.read(
        { requestUri: serviceUri, user: "USER", password: "PASS" },
        function (data){
          alert("success");
          //print_r(data);
        },
        function (err) {
          //Error Callback
          alert("Error occurred " + err.message);
          print_r(err);
        }) ;
    }
  

    function print_r(theObj){
      if(theObj.constructor == Array ||
         theObj.constructor == Object){
        document.write("<ul>")
        for(var p in theObj){
          if(theObj[p].constructor == Array||
             theObj[p].constructor == Object){
    document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
            document.write("<ul>")
            print_r(theObj[p]);
            document.write("</ul>")
         } else {
    document.write("<li>["+p+"] => "+theObj[p]+"</li>");
          }
        }
        document.write("</ul>")
      }
    }
</script>
</body>
</html>