unityでdocomo雑談対話apiを使用したいです。
しかし、データをpostしてもError downloading: 400 Bad Requestが出ます。
using System.Collections; using System.Collections.Generic; using System.Text; using UnityEngine; using MiniJSON; public class Brain : MonoBehaviour { private string url = "https://api.apigw.smt.docomo.ne.jp/dialogue/v1/dialogue?APIKEY="; private string key = "xxxxxxxxxxxxxxxxxxxx"; // API key private string text = "こんにちは"; // Use this for initialization void Start () { this.url += key; StartCoroutine("connect"); } // Update is called once per frame void Update () { } private IEnumerator connect() { Hashtable header = new Hashtable(); header.Add("Content-type", "application/json"); string postData = "{'utt':'" + text + "', 'context':'', 'mode':'dialog'}"; byte[] data = System.Text.Encoding.UTF8.GetBytes(postData); WWW www = new WWW (url,data,header); yield return www; if(!string.IsNullOrEmpty(www.error)) { print( "Error downloading: " + www.error ); } else { string jsonText = www.text; var json = Json.Deserialize (jsonText) as Dictionary<string, object>; foreach (var jsondata in json) { Debug.Log ("key名:" + jsondata.Key + " value値" + jsondata.Value); } } } }
WWWのコンストラクタは指示通りにパラメータを入れています。
エラー原因となっているプログラムが必ずあると思うのですが、自分ではわかりません。
ちなみにpythonでアクセスしたときは成功するので、アクセス制限がかかっているわけではありません。
原因がわかる方教えていただきたいです。よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/23 00:48