Successfully sent a SOAP service call using Typescript Angular 2, receiving a response with status code 200 OK for the specified URL: null

Upon making a SOAP service call with my Nativescript application, I am encountering a situation where the response status is '200' but the response itself states 'Response with status: 200 OK for URL: null'. The code snippet I am using involves a post method and is outlined below,

import { Injectable } from 'angular2/core';
import { Http, Request, Response, Headers, RequestMethod, RequestOptions } from 'angular2/http';
import { Observable } from 'rxjs/Observable';

@Injectable()
export class PaymentsService {

private body: string = `<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<HelloWorld xmlns="http://bernera.zapto.org/" />
</soap:Body>
</soap:Envelope>`;

private result;

constructor(private http: Http) { }

callSOAP() {

var headers = new Headers();
headers.append('Content-Type', 'text/xml');
headers.append('Access-Control-Request-Method', 'POST');
headers.append('Access-Control-Request-Headers', 'X-Custom-Header');
headers.append('Access-Control-Allow-Origin', 'http://localhost:3004');

this.http.post('http://bernera.zapto.org/astronomy/astronomy.asmx',
this.body,
{ headers: headers })
.subscribe(
data => this.result = data,
err => this.logError(err),
() => console.log('Call complete')
);

alert('result ' + this.result);
}

logError(err) {
console.error('There was an error: ' + err.statusText);
alert('There was an error: ' + err.statusText);
}

}

Answer №1

Once your server responds, anything you include in the subscribe method will be executed asynchronously. However, it seems like in your scenario, you are trying to access this.result before it has been populated.

this.http.post(whatever_url, this.body, { headers: headers }).subscribe(
   data => {
       this.result = data; 
       alert(this.data); // should display something
   },
   err => this.logError(err),
   () => console.log('Call complete')
);
alert(this.data); // <--- null, as the server's response hasn't been received yet

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountered a problem when trying to show a PDF viewer within a Bootstrap modal

Trying to preview a PDF using a bootstrap modal, but encountering an error: Error: Unable to initialize viewer. TypeError: Cannot read property 'div' of undefined When the modal is called, the PDF does not display initially. However, if the s ...

How can one generate a mapped, conditional type in TypeScript that eliminates properties of type string | null?

Here's my latest unsuccessful attempt before seeking guidance. Can anyone point out my mistakes? Thank you! interface Entity { id: string; title: string | null; } interface AnotherEntity { id: string; title: string; } type ExcludeNullFields& ...

Steps for resolving the Angular datepicker filter issue

Currently, I am facing an issue with filtering dates to display data based on a specified range. The problem arises when the FROM and TO dates are the same, as it fails to show the data for the selected date. For instance, in the following scenario: FROM: ...

Creating a Checkbox-enabled Muiv5 TreeView for an array of objects: Step-by-step guide

Currently, I am utilizing the muiv5 treeview component to construct a treeview dropdown. Unfortunately, the component does not have built-in checkbox support for selection/deselection. However, after conducting some research, I managed to find a somewhat s ...

Tips for modifying the background color of an individual page in Ionic 3 and above

https://i.stack.imgur.com/t2mDw.pngI am just starting with Ionic and I'm attempting to modify the CSS of a single page by changing the background color to something different, like green, for example. I know that I can make global changes, but in this ...

Issue with sending headers in HttpClient.post method in Angular 8

I have successfully implemented the following code: this.http.post (TGT_IP,body, {responseType: 'arraybuffer'}).subscribe( (val) => { console.log("POST call successful value returned in body", val); ...

Node.js app hosted on Azure Functions unable to resolve NPM dependencies

I set up a Node (TypeScript) Azure Function application using the VSCode Azure Function extension. While checking the deployment output, I noticed the following log line: Started postDeployTask "npm install (functions)". Despite this, I couldn&a ...

Using the spread operator to modify an array containing objects

I am facing a challenge with updating specific properties of an object within an array. I have an array of objects and I need to update only certain properties of a single object in that array. Here is the code snippet I tried: setRequiredFields(prevRequir ...

Cookie authentication in CodeIgniter with Angular HTTP requests in Ionic 3

I am experiencing difficulties sending POST/get requests to the server. When using the Postman Chrome extension, everything works fine. However, when attempting to use Angular Http (not HttpClient) in Ionic, I encounter errors. The first error is related t ...

DOM Manipulation in Angular

I encountered an issue in the spec file where DOMHelper was not found and could not be imported, despite adding it with "npm I dom-helpers". How can I resolve this error? I will also provide a screenshot for reference. Click here to view the image Module ...

What is the best way to experiment with transclusion (ng-content) in Angular2?

I have a specific component that I need to test, here is the code: import {Component, OnInit, Input} from "@angular/core"; @Component({ selector: 'column', template: '<ng-content></ng-content>', host: { ...

The field 'password' is not found in the 'User' array type

I'm encountering an issue with my Typescript code: Property 'password' does not exist on type 'User[]'.ts(2339). Do I need to create an interface or something similar? Thank you in advance. usersRouter.post("/", async ...

How can I extract a value from an object that is readonly, using a formatted string as the key?

I encountered a situation where I have code resembling the following snippet. It involves an object called errorMessages and multiple fields. Each field corresponds to various error messages in the errorMessages object, but using a formatted string to retr ...

The initial rendering of components is not displayed by Vue Storybook

The functionality of the storybook is effective, but initially, it fails to "render" the component. By examining the screenshot, we can deduce that the component-template is being utilized in some way, as otherwise, the basic layout of the component would ...

Nextjs 13 brings exciting new features, one of which is the ability to call getStatic

I am working on a Next.js 13 application where I have organized my files in the 'app' directory instead of the usual 'pages'. All pages are statically generated during build time and data is fetched from an external API. https://i.sstat ...

In response to resolving an HTTP header issue with a status of 200 ok during API testing with Postman, what steps can be taken

Hello everyone, I am new to the world of Angular and facing some issues while learning. Following a tutorial on YouTube, I tried to replicate the process with a few modifications. Initially, my get API worked fine when tested with Postman, and the post API ...

How can you apply an active class using React-Router?

My React-Router navigation issue nav.tsx import React from 'react' import { menu } from './menu' import { Link } from 'react-router-dom' import styles from './HamburgerMenu.module.scss' const HamburgerMenu: React.F ...

Searching for a streamlined approach to retrieve a segment of a string

I'm currently working with JavaScript and TypeScript. Within my code, I encountered a scenario where I have a string that might contain certain tags indicating importance or urgency. Here are a couple of examples: A: "Remind me to go to the store to ...

The class instances are not invoking the decorators

I'm experiencing issues with my decorators. It seems that the decorators are not being invoked on every instance of the class. While I understand that decorators are called during declaration time, I am wondering if there is a way to call them for eac ...

Implementing ngFor to Iterate Through a JSON Object in Angular 6

Iterate through the object list retrieved from a JSON object Here is the JSON object that I have fetched: { "0": { "0": null, "1": "Consolidated Statements of Changes in Stockholders\u2019 Deficit", "2": null, "3": "", "4": "" ...