Sending Data to Server using Express(Node.js)

Thread is closed for posting
2 posts, 0 answers
  1. Sumit
    Sumit avatar
    1 posts
    Member since:
    Sep 2016

    Posted 06 Oct 2016 Link to this post

    I am new in angular2-Nativescript when i am sending data to server which is in Express(Node.js). Some function are able to send data to server but some function is not working.

    Working Code

    login(user: User) {
        let headers = new Headers();
        headers.append("Content-Type", "application/json");
          Config.apiUrl + "login",
            password: user.password
          { headers: headers }
          .map(response => response.json())
          .map((response) => {
            if (response.authentication == true) {
              alert('Login Successful');
              console.log("returning result = ", JSON.stringify(response.result));
              console.log("response == ", JSON.stringify(response.result));
              localStorage.setItem('userInfo1', JSON.stringify(response.result));
            } else {


    Not Working Code

    verify(user: User) {
        console.log(JSON.stringify({ user }));
        let headers = new Headers();
        headers.append("Content-Type", "application/json");
          Config.apiUrl + "verify",
            verificationCode: user.verificationCode
          { headers: headers }
          .map(response => response.json())
          .map((response) => { })

    I am facing this issue in ios
  2. Nikolay Iliev
    Nikolay Iliev avatar
    351 posts

    Posted 06 Oct 2016 Link to this post

    Hello Sumit,

    I have examed your code, still without a detail on what is the output behaviour I can not guide you to a reasonable solution. We will need the error you are receiving or/and the behaviour you are expecting and what is really happening after you try to execute the verify function in your application.

    However, there is some possible reason for your code not to work in iOS (of course, the following are just a suggestions).

    One thing is that on iOS you can not make the request to HTTP but by default only to HTTPS. You will receive transport protocol security error if you try that. Another possible issue is when you are receiving the response as JSON you are not actually working with it.
    response) => { }
    Is that the expected behaviour!? 
    Or maybe you need to log the response and further parse the response data like this

        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ username: this.user , password: this.pass })
    }).then(response => {
        return response.json();
    }).then(res => {
        var jsonObjectBody = JSON.parse(; // parse the data need to JSON
        this.message = "Data successfully send by user " + jsonObjectBody.username;
    }).catch(err => {
        // Error

    We will wait for your error log and detailed description to the issue to help you out further.

    Nikolay Iliev
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top