Get/Set cookie while using dart web app http












1















I am working on an AngularDart web app.
I need to retrieve a cookie from a json server that works with cookie authentication.
So on connection, I have to post credentials in body, then the server give me back a response containing the cookie.



import 'package:http/browser_client.dart';
Response response = await _http.post(_loginUrl, body: json.encode(datas));


The response is ok, I get 200 statuscode and the json response from the server, but impossible to find the cookie while in Postman I do get it.
So how to retrieve cookies from response?



EDIT: Informations returned from the server to postman :



ASP.NET_SessionId=03e95c12-6098-4f07-b9a9-054377b0311d; path=/; domain=.www.xxxxx.fr; HttpOnly; Expires=Tue, 19 Jan 2038 03:14:07 GMT;


EDIT: This is the raw headers from the server to the Dart app :



t=1462088 [st=142]        HTTP_TRANSACTION_READ_RESPONSE_HEADERS
--> HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/8.5
Set-Cookie: ASP.NET_SessionId=f229a77e-5eb6-4c6c-9c57-9280947cb434; path=/; HttpOnly
X-Powered-By: ASP.NET
Access-Control-Allow-Origin: *
Date: Fri, 30 Nov 2018 09:52:50 GMT
Content-Length: 22443


So the server sends back the cookie, but the browser does not seem to save it ...



Ok so finally, a problem was found on the API server, the developer did not check correctly the cookie. Generally, only one cookie is sent to this server, so in its code, it took the first... But from a browser, severals cookie can be sent at the same time. So he made some change to check the good one...










share|improve this question





























    1















    I am working on an AngularDart web app.
    I need to retrieve a cookie from a json server that works with cookie authentication.
    So on connection, I have to post credentials in body, then the server give me back a response containing the cookie.



    import 'package:http/browser_client.dart';
    Response response = await _http.post(_loginUrl, body: json.encode(datas));


    The response is ok, I get 200 statuscode and the json response from the server, but impossible to find the cookie while in Postman I do get it.
    So how to retrieve cookies from response?



    EDIT: Informations returned from the server to postman :



    ASP.NET_SessionId=03e95c12-6098-4f07-b9a9-054377b0311d; path=/; domain=.www.xxxxx.fr; HttpOnly; Expires=Tue, 19 Jan 2038 03:14:07 GMT;


    EDIT: This is the raw headers from the server to the Dart app :



    t=1462088 [st=142]        HTTP_TRANSACTION_READ_RESPONSE_HEADERS
    --> HTTP/1.1 200 OK
    Content-Type: application/json; charset=utf-8
    Server: Microsoft-IIS/8.5
    Set-Cookie: ASP.NET_SessionId=f229a77e-5eb6-4c6c-9c57-9280947cb434; path=/; HttpOnly
    X-Powered-By: ASP.NET
    Access-Control-Allow-Origin: *
    Date: Fri, 30 Nov 2018 09:52:50 GMT
    Content-Length: 22443


    So the server sends back the cookie, but the browser does not seem to save it ...



    Ok so finally, a problem was found on the API server, the developer did not check correctly the cookie. Generally, only one cookie is sent to this server, so in its code, it took the first... But from a browser, severals cookie can be sent at the same time. So he made some change to check the good one...










    share|improve this question



























      1












      1








      1








      I am working on an AngularDart web app.
      I need to retrieve a cookie from a json server that works with cookie authentication.
      So on connection, I have to post credentials in body, then the server give me back a response containing the cookie.



      import 'package:http/browser_client.dart';
      Response response = await _http.post(_loginUrl, body: json.encode(datas));


      The response is ok, I get 200 statuscode and the json response from the server, but impossible to find the cookie while in Postman I do get it.
      So how to retrieve cookies from response?



      EDIT: Informations returned from the server to postman :



      ASP.NET_SessionId=03e95c12-6098-4f07-b9a9-054377b0311d; path=/; domain=.www.xxxxx.fr; HttpOnly; Expires=Tue, 19 Jan 2038 03:14:07 GMT;


      EDIT: This is the raw headers from the server to the Dart app :



      t=1462088 [st=142]        HTTP_TRANSACTION_READ_RESPONSE_HEADERS
      --> HTTP/1.1 200 OK
      Content-Type: application/json; charset=utf-8
      Server: Microsoft-IIS/8.5
      Set-Cookie: ASP.NET_SessionId=f229a77e-5eb6-4c6c-9c57-9280947cb434; path=/; HttpOnly
      X-Powered-By: ASP.NET
      Access-Control-Allow-Origin: *
      Date: Fri, 30 Nov 2018 09:52:50 GMT
      Content-Length: 22443


      So the server sends back the cookie, but the browser does not seem to save it ...



      Ok so finally, a problem was found on the API server, the developer did not check correctly the cookie. Generally, only one cookie is sent to this server, so in its code, it took the first... But from a browser, severals cookie can be sent at the same time. So he made some change to check the good one...










      share|improve this question
















      I am working on an AngularDart web app.
      I need to retrieve a cookie from a json server that works with cookie authentication.
      So on connection, I have to post credentials in body, then the server give me back a response containing the cookie.



      import 'package:http/browser_client.dart';
      Response response = await _http.post(_loginUrl, body: json.encode(datas));


      The response is ok, I get 200 statuscode and the json response from the server, but impossible to find the cookie while in Postman I do get it.
      So how to retrieve cookies from response?



      EDIT: Informations returned from the server to postman :



      ASP.NET_SessionId=03e95c12-6098-4f07-b9a9-054377b0311d; path=/; domain=.www.xxxxx.fr; HttpOnly; Expires=Tue, 19 Jan 2038 03:14:07 GMT;


      EDIT: This is the raw headers from the server to the Dart app :



      t=1462088 [st=142]        HTTP_TRANSACTION_READ_RESPONSE_HEADERS
      --> HTTP/1.1 200 OK
      Content-Type: application/json; charset=utf-8
      Server: Microsoft-IIS/8.5
      Set-Cookie: ASP.NET_SessionId=f229a77e-5eb6-4c6c-9c57-9280947cb434; path=/; HttpOnly
      X-Powered-By: ASP.NET
      Access-Control-Allow-Origin: *
      Date: Fri, 30 Nov 2018 09:52:50 GMT
      Content-Length: 22443


      So the server sends back the cookie, but the browser does not seem to save it ...



      Ok so finally, a problem was found on the API server, the developer did not check correctly the cookie. Generally, only one cookie is sent to this server, so in its code, it took the first... But from a browser, severals cookie can be sent at the same time. So he made some change to check the good one...







      dart angular-dart dart-html






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 30 '18 at 12:49







      ebelair

















      asked Nov 28 '18 at 16:19









      ebelairebelair

      441418




      441418
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Postman should show that this is an HttpOnly cookie that can't be read from JavaScript (and the same applies for Dart of course)



          See also https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Secure_and_HttpOnly_cookies



          The cookie will be sent back to the server automatically therefore there is no need to read it from JavaScript. Allowing access from JavaScript only undermines security.






          share|improve this answer
























          • That's the problem, the cookie is not sent back to the server automatically and I don't know why. I tried in http & https.

            – ebelair
            Nov 30 '18 at 8:06











          • Perhaps the server you are accessing is not the same as the one that issued the cookie. A different port is already considered a different server for the browser.

            – Günter Zöchbauer
            Nov 30 '18 at 8:07











          • It is exactly the same

            – ebelair
            Nov 30 '18 at 8:24






          • 1





            Finally, I found the answer..... There was a bug on the server ... The developer has made some corrections and now it's working.... make me crazy lol

            – ebelair
            Nov 30 '18 at 10:59






          • 1





            I've edited my post to explain the crime scene.

            – ebelair
            Nov 30 '18 at 12:49











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53523857%2fget-set-cookie-while-using-dart-web-app-http%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Postman should show that this is an HttpOnly cookie that can't be read from JavaScript (and the same applies for Dart of course)



          See also https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Secure_and_HttpOnly_cookies



          The cookie will be sent back to the server automatically therefore there is no need to read it from JavaScript. Allowing access from JavaScript only undermines security.






          share|improve this answer
























          • That's the problem, the cookie is not sent back to the server automatically and I don't know why. I tried in http & https.

            – ebelair
            Nov 30 '18 at 8:06











          • Perhaps the server you are accessing is not the same as the one that issued the cookie. A different port is already considered a different server for the browser.

            – Günter Zöchbauer
            Nov 30 '18 at 8:07











          • It is exactly the same

            – ebelair
            Nov 30 '18 at 8:24






          • 1





            Finally, I found the answer..... There was a bug on the server ... The developer has made some corrections and now it's working.... make me crazy lol

            – ebelair
            Nov 30 '18 at 10:59






          • 1





            I've edited my post to explain the crime scene.

            – ebelair
            Nov 30 '18 at 12:49
















          0














          Postman should show that this is an HttpOnly cookie that can't be read from JavaScript (and the same applies for Dart of course)



          See also https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Secure_and_HttpOnly_cookies



          The cookie will be sent back to the server automatically therefore there is no need to read it from JavaScript. Allowing access from JavaScript only undermines security.






          share|improve this answer
























          • That's the problem, the cookie is not sent back to the server automatically and I don't know why. I tried in http & https.

            – ebelair
            Nov 30 '18 at 8:06











          • Perhaps the server you are accessing is not the same as the one that issued the cookie. A different port is already considered a different server for the browser.

            – Günter Zöchbauer
            Nov 30 '18 at 8:07











          • It is exactly the same

            – ebelair
            Nov 30 '18 at 8:24






          • 1





            Finally, I found the answer..... There was a bug on the server ... The developer has made some corrections and now it's working.... make me crazy lol

            – ebelair
            Nov 30 '18 at 10:59






          • 1





            I've edited my post to explain the crime scene.

            – ebelair
            Nov 30 '18 at 12:49














          0












          0








          0







          Postman should show that this is an HttpOnly cookie that can't be read from JavaScript (and the same applies for Dart of course)



          See also https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Secure_and_HttpOnly_cookies



          The cookie will be sent back to the server automatically therefore there is no need to read it from JavaScript. Allowing access from JavaScript only undermines security.






          share|improve this answer













          Postman should show that this is an HttpOnly cookie that can't be read from JavaScript (and the same applies for Dart of course)



          See also https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Secure_and_HttpOnly_cookies



          The cookie will be sent back to the server automatically therefore there is no need to read it from JavaScript. Allowing access from JavaScript only undermines security.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 28 '18 at 20:29









          Günter ZöchbauerGünter Zöchbauer

          333k711009942




          333k711009942













          • That's the problem, the cookie is not sent back to the server automatically and I don't know why. I tried in http & https.

            – ebelair
            Nov 30 '18 at 8:06











          • Perhaps the server you are accessing is not the same as the one that issued the cookie. A different port is already considered a different server for the browser.

            – Günter Zöchbauer
            Nov 30 '18 at 8:07











          • It is exactly the same

            – ebelair
            Nov 30 '18 at 8:24






          • 1





            Finally, I found the answer..... There was a bug on the server ... The developer has made some corrections and now it's working.... make me crazy lol

            – ebelair
            Nov 30 '18 at 10:59






          • 1





            I've edited my post to explain the crime scene.

            – ebelair
            Nov 30 '18 at 12:49



















          • That's the problem, the cookie is not sent back to the server automatically and I don't know why. I tried in http & https.

            – ebelair
            Nov 30 '18 at 8:06











          • Perhaps the server you are accessing is not the same as the one that issued the cookie. A different port is already considered a different server for the browser.

            – Günter Zöchbauer
            Nov 30 '18 at 8:07











          • It is exactly the same

            – ebelair
            Nov 30 '18 at 8:24






          • 1





            Finally, I found the answer..... There was a bug on the server ... The developer has made some corrections and now it's working.... make me crazy lol

            – ebelair
            Nov 30 '18 at 10:59






          • 1





            I've edited my post to explain the crime scene.

            – ebelair
            Nov 30 '18 at 12:49

















          That's the problem, the cookie is not sent back to the server automatically and I don't know why. I tried in http & https.

          – ebelair
          Nov 30 '18 at 8:06





          That's the problem, the cookie is not sent back to the server automatically and I don't know why. I tried in http & https.

          – ebelair
          Nov 30 '18 at 8:06













          Perhaps the server you are accessing is not the same as the one that issued the cookie. A different port is already considered a different server for the browser.

          – Günter Zöchbauer
          Nov 30 '18 at 8:07





          Perhaps the server you are accessing is not the same as the one that issued the cookie. A different port is already considered a different server for the browser.

          – Günter Zöchbauer
          Nov 30 '18 at 8:07













          It is exactly the same

          – ebelair
          Nov 30 '18 at 8:24





          It is exactly the same

          – ebelair
          Nov 30 '18 at 8:24




          1




          1





          Finally, I found the answer..... There was a bug on the server ... The developer has made some corrections and now it's working.... make me crazy lol

          – ebelair
          Nov 30 '18 at 10:59





          Finally, I found the answer..... There was a bug on the server ... The developer has made some corrections and now it's working.... make me crazy lol

          – ebelair
          Nov 30 '18 at 10:59




          1




          1





          I've edited my post to explain the crime scene.

          – ebelair
          Nov 30 '18 at 12:49





          I've edited my post to explain the crime scene.

          – ebelair
          Nov 30 '18 at 12:49




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53523857%2fget-set-cookie-while-using-dart-web-app-http%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

          Calculate evaluation metrics using cross_val_predict sklearn

          Insert data from modal to MySQL (multiple modal on website)