亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將服務連接到 Cloud Foundry 應用程序?

如何將服務連接到 Cloud Foundry 應用程序?

慕哥9229398 2023-07-06 18:24:12
我是 IBM 云的新手,我正在嘗試構建一個應用程序,我可以在其中編寫文本,按下按鈕,然后由返回 JSON 的服務音分析器分析該文本,以便我可以顯示它。我創建了該服務的一個實例,并使用服務上的“連接”選項卡將其連接到我的應用程序(工具鏈)。我的應用程序的 app.js 文件中也有此代碼:const ToneAnalyzerV3 = require('ibm-watson/tone-analyzer/v3');const { IamAuthenticator } = require('ibm-watson/auth');const toneAnalyzer = new ToneAnalyzerV3({  version: '2019-10-10',  authenticator: new IamAuthenticator({    apikey: [API key found in service credentials],  }),  url: [API url found in service credentials],});app.get('/', function(req, res) {  res.render('index');});app.post('/api/tone', async function(req, res, next) {  try {    const { result } = await toneAnalyzer.tone(req.body);    res.json(result);  } catch (error) {    next(error);  }});問題是,當我在 javascript 上進行以下調用時:$.post( "/api/tone", {text: textInput}, function(data){        console.log(data);    });我收到錯誤:500(內部服務器錯誤)。有人知道我做錯了什么嗎?
查看完整描述

1 回答

?
慕蓋茨4494581

TA貢獻1850條經驗 獲得超11個贊

問題是您發送的內容req.body是要進行語氣分析的。如果您查看 API 文檔 - https://cloud.ibm.com/apidocs/tone-analyzer?code=node#tone - 您會發現您只需要發送


const toneParams = {

  toneInput: { 'text': text },

  contentType: 'application/json',

};

我非常懷疑它是否req.body有一個toneInput字段,如果它確實有contentType它可能不會被設置為允許的值之一。


查看完整回答
反對 回復 2023-07-06
  • 1 回答
  • 0 關注
  • 144 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號