title: Setting request cookies angular2 http post request
body: <p>I have a login service that performs an http request (to a php backend server) and returns a cookie. After login this cookie is needs to be used in all further requests done by the client.</p>
  
  <p>loginservice:</p>
  
  <pre class="lang-js prettyprint-override"><code>   login(userCredentials:UserCredentials):Observable&lt;any&gt; {    
          this.request.ServiceType = "Connect"
          this.request.SessionId = "sessionlessrequest"
          this.request.Compression = "no"
          this.request.Parameters = userCredentials;
          let jsonRequest = JSON.stringify(this.request)
          return this.http.post("http://localhost/request.php", "data="+ jsonRequest,
              { headers: new Headers({
                  'Content-Type': 'application/x-www-form-urlencoded'
              })
              }).map( (responseData) =&gt; {
              this.apiResponse = responseData.json() as ApiResponse
              if (!this.apiResponse.Error) {
                  this.sessionData.next(this.apiResponse.Data as UserSessionData)
                  this.sessionData.asObservable().share
              } else {
                  console.log(this.apiResponse.ErrorMessage)
              }
              return null
          })
  </code></pre>
  
  <p>When doing this call, the cookie response is like this:<br>
  <a href="https://i.stack.imgur.com/LzqHO.png" rel="noreferrer"><img src="https://i.stack.imgur.com/LzqHO.png" alt="getcookie"></a></p>
  
  <p>I see that I get the session_id from session_start (on my php server)</p>
  
  <p>I when doing the request :</p>
  
  <pre class="lang-js prettyprint-override"><code>searchExams(searchObject:SearchObject):Observable&lt;any&gt;{
          let headers = new Headers();
          headers.append('Content-Type', 'application/x-www-form-urlencoded',)
          let options = new RequestOptions({ headers: headers, withCredentials: true});
          this.request.ServiceType = ServiceType.SearchExams;
          this.request.SessionId = this.userSessionData.SessionId;
          this.request.Compression = "no"
          this.request.Parameters = searchObject;
          let jsonRequest = JSON.stringify(this.request)
          console.log(jsonRequest)
          return this.http.post("http://localhost/request.php", "data="+ jsonRequest, options
              ).map( (responseData) =&gt; {
              this.apiResponse = responseData.json() as ApiResponse
              if (!this.apiResponse.Error) {
  ....
  </code></pre>
  
  <p>I see that the request cookie is totally different from the one I got from the server. Moreover it is always the same PHPSESSID
  <a href="https://i.stack.imgur.com/UhPGH.png" rel="noreferrer"><img src="https://i.stack.imgur.com/UhPGH.png" alt="postrequest"></a></p>
  
  <p>Do I need to set the request cookie? How?
  What am I missing?</p>
  
  <p>Thanks....</p>