当我在localhost时,我有一个urlshortener代码,但如果在其他地方部署(或者如果我通过IP地址访问我的本地应用程序),则无法工作:
这是我的代码:
insertUrl(longUrl) {
let headers = new Headers({
'Content-Type': 'application/json',
'Accept': 'application/json'
});
let body = {
'longUrl': longUrl
};
let options = new RequestOptions({
method: RequestMethod.Post,
headers: headers,
body: body
});
return this.http.post(UrlShortener.URL_SHORTENER_API + '?key=' + '<MY APY KEY>', body, options)
.map((res: Response) => res.json());
}
这可能是一个非常简单的答案,但我无法弄清楚。任何帮助表示赞赏!
错误:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Invalid Value",
"locationType": "parameter",
"location": "resource.longUrl"
}
],
"code": 400,
"message": "Invalid Value"
}
}