typescript 怎么调用http的create接口

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript 怎么调用http的create接口相关的知识,希望对你有一定的参考价值。

参考技术A /// <summary>
/// 发起一个HTTP请求(以POST方式)
/// </summary>
/// <param name="url"></param>
/// <param name="param"></param>
/// <returns></returns>
public static string HttpPost(string url, string param = "")

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.Accept = "*/*";
request.Timeout = 10000;
request.AllowAutoRedirect = false;本回答被提问者采纳

typescript Observable.create

export class AppComponent {
  title = 'app';
 
  observable$;
 
  ngOnInit() {
    // create an observable
    this.observable$ = Observable.create((observer) => {
      observer.next(1);
      observer.next(2);
      observer.next(3);
      observer.complete();
    });
    this.observable$.subscribe(
      value => console.log(value),
      err => {},
      () => console.log('this is the end')
    );    
  }
 
  ngOnDestroy() {
    // unsubscribe an observable, otherwise it'll keep on listening even if the component is destroyed
    this.observable$.unsubscribe();
  }
}
// Logs
// 1
// 2
// 3
// "this is the end"

/*
Calling next with a value will emit that value to the observer. 
Calling complete means that Observable finished emitting and will not do anything else. 
Calling error means that something went wrong - value passed to error method should provide details 
on what exactly happened.

A well-formed Observable can emit as many values as it needs via next method, but complete and error methods
can be called only once and nothing else can be called thereafter. If you try to invoke next, complete or 
error methods after created Observable already completed or ended with an error, these calls will be ignored
to preserve so called Observable Contract. Note that you are not required to call complete at any point 
- it is perfectly fine to create an Observable that never ends, depending on your needs.
*/

const observable = Rx.Observable.create((observer) => {
  observer.error('something went really wrong...');
});

observable.subscribe(
  value => console.log(value), // will never be called
  err => console.log(err),
  () => console.log('complete') // will never be called
);

// Logs
// "something went really wrong..."

以上是关于typescript 怎么调用http的create接口的主要内容,如果未能解决你的问题,请参考以下文章

create-react-app 可以与 TypeScript 一起使用吗

http接口调用超时,怎么解决

TypeScript - 我无法使用 Angular 2 使用 http get 调用我的 json

Typescript http.get 错误:没有重载匹配此调用

将 create-react-app 从 javascript 迁移到 typescript

typescript Observable.create