找不到指定的内容类型 - 错误611 - NativeScript

时间:2017-12-08 05:23:49

标签: nativescript angular2-nativescript

我正在按照NativeScript的步骤tutorial进行操作,但我面临以下问题:

当我尝试通过Angular服务发布帖子请求时,我收到以下错误:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?page=([^&\ ]+)
RewriteRule ^/?$ /%1? [L,R=301]

我的代码看起来与NativeScript官方文档中的代码非常相似:

JS: {"message":"The specified content type was not found.","errorCode":611}

组件类:

import { Injectable } from '@angular/core';
import { Http, Headers, Response } from '@angular/http';
import { User } from './user';
import { Config } from '../config';
import { Observable } from 'rxjs/Rx';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';

@Injectable()
export class UserService {
    constructor(private _http: Http) { }

    register(user: User): Observable<Response> {
        const headers = new Headers();
        headers.append('Content-Type', 'application/json');
        const url = `${Config.apiUrl}/Users`;
        const body = JSON.stringify({
            Username: user.email,
            Email: user.email,
            Password: user.password
        });

        return this._http.post(url, body, { headers })
            .catch(this.handleErrors);
    }

    handleErrors(error: Response) {
        console.error(JSON.stringify(error.json()));
        return Observable.throw(error);
    }
}

在Android和IO下测试,都会引发同样的错误。

在这种情况下,

不是signUp() { this._user.register(this.user).subscribe( () => { alert('Your account has been successfully created.'); this.toggleDisplay(); }, () => { // errors here... alert('Unfortunately we were unable to create your account.'); } ); } 预期application/json吗? 如果我更改了类型,我会收到另一个错误,说明类型丢失或无效。

有人可以指出我错过了什么吗?

0 个答案:

没有答案