当前位置:  开发笔记 > 编程语言 > 正文

在Angular 5上从HTTPClient检索XML

如何解决《在Angular5上从HTTPClient检索XML》经验,为你挑选了0个好方法。

我正在尝试使用来自Angular 的HttpClient从SOAP API检索xml

这是我的app.component.html上的内容


这是在我的app.component.ts上

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { HttpErrorResponse } from '@angular/common/http';
import { HttpHeaders } from '@angular/common/http';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {

  results: string[];
  constructor(private http: HttpClient) {
    console.log('constructor opened');

  }
  ngOnInit(): void{
    console.log('onInit opened'); 

    }

  onClickMe(){
      var emp = '<>';
      var login = '<>';
      var pass = '<>';
      var id = "<>";

      const body = "\r\n\r\n  \r\n    \r\n      "+emp+"\r\n      "+ login +"\r\n      "+ pass +"\r\n      "+ id +"\r\n    \r\n  \r\n";
      const url = "<>";
      console.log('onClickme opened');

      this.http.post(url, body, {
        headers: new HttpHeaders()
        .set('Content-Type', 'text/xml') 
        .append('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH,OPTIONS') 
        .append('Access-Control-Allow-Origin', '*')
        .append('Access-Control-Allow-Headers', "Access-Control-Allow-Headers, Access-Control-Allow-Origin, Access-Control-Request-Method")
  }).subscribe(data => {
        console.log(data);

      },
      (err: HttpErrorResponse) => {
        if (err.error instanceof Error) {
          // A client-side or network error occurred. Handle it accordingly.
          console.log('An error occurred:', err.error.message);
        } else {
          // The backend returned an unsuccessful response code.
          // The response body may contain clues as to what went wrong,
          console.log(`Backend returned code ${err.status}, body was: ${err.error}`);
        }
      }
    );

  }


}

因此,我使用Postman进行了相同的请求,并完全按照成功的POST的工作复制了网址和正文。我试图使用Angular 5来做到这一点,但它不起作用,它返回以下消息:

Backend returned code 200, body was: [object Object]

有人知道我该怎么做吗?该请求获得了200个代码,但响应方式不正确。

感谢您的帮助!

推荐阅读
mylvfamily
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有