【问题标题】:Angular 2 Http post errorAngular 2 Http发布错误
【发布时间】:2016-03-14 23:49:07
【问题描述】:

我有一个 Ionic 2 应用程序,可以从 Facebook 获取一些事件。我正在尝试使用 batch containing multiple requests 向 Graph Api 发送发布请求,但我的订阅总是返回此错误:

{"_body":"","status":404,"statusText":"Ok","headers":{"Client-Via", ["shouldInterceptRequest"]},"type":2,"url":"https://graph.facebook.com/"}

我的组件内的订阅:

this.eventListService.get()
  .subscribe(
    response => this.response = response,
    error => this.error = error
  )

事件列表服务:

import {Injectable} from '../../node_modules/angular2/core';
import {Http, Headers, URLSearchParams} from '../../node_modules/angular2/http';
import {Observable} from '../../node_modules/rxjs/Rx';
import {AuthenticationService} from '../user/authentication.service';

@Injectable()
export class EventListService {
  private fields: string = 'id, cover, name, start_time, place, attending_count, interested_count, rsvp_status';

  constructor(
    private http: Http,
    private authenticationService: AuthenticationService
  ) {}

  get() {
    return Observable
      .fromPromise(this.authenticationService.getAccessToken())
      .flatMap(accessToken => this.synchronize(accessToken));
  }

  synchronize(accessToken) {
    const today = new Date();
    today.setHours(0, 0, 0, 0);
    const todayTimestamp = today.getTime();

    const batch = [{...}];

    const headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded');

    const body = new URLSearchParams();
    body.append('access_token', accessToken);
    body.append('batch', JSON.stringify(batch));

    return this.http
      .post('https://graph.facebook.com', body.toString(), { headers })
      .map(response => response.json());
  }
}

知道为什么我在发出请求时收到此错误吗?

【问题讨论】:

标签: http angular rxjs observable ionic2


【解决方案1】:

404 错误 = 未找到 (https://en.wikipedia.org/wiki/HTTP_404)

因此,您尝试访问的任何资源的 url 都可能错误,或者您的连接存在其他问题。

确实 - 如果我手动尝试从浏览器导航到 https://graph.facebook.com,我会收到 404 错误。

由于这是使用 https 协议,因此也可能是身份验证问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-05
    • 2018-01-21
    • 1970-01-01
    • 2017-12-23
    • 2017-02-24
    • 2023-04-04
    相关资源
    最近更新 更多