如何在不出现Unsupported media type错误的情况下将数据从React表单发送到Django后端服务器?

时间:2019-08-02 12:45:21

标签: python django reactjs api django-rest-framework

在这里反应新手,我试图在React中为基于Django的后端创建一个简单的表单,并且不断收到错误reEng.SetInputToDefaultAudioDevice();。我的后端根本没有发送数据。

我在这里做什么错了?

using System;
using System.Windows.Forms;
using System.Speech.Recognition;
using System.Speech.Synthesis;



namespace vbot
{
    public partial class Form1 : Form
    {
        SpeechRecognitionEngine reEng = new SpeechRecognitionEngine();
        SpeechSynthesizer synth = new SpeechSynthesizer();
        public Form1()
        {
            InitializeComponent();
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Choices command = new Choices();
            command.Add(new string[] { "hello", "hi", "say hello", "what is your name?" });
            GrammarBuilder gbuilder = new GrammarBuilder();
            gbuilder.Append(command);
            Grammar gramer = new Grammar(gbuilder);
            reEng.LoadGrammarAsync(gramer);
            reEng.SetInputToDefaultAudioDevice();
            reEng.SpeechRecognized += ReEng_SpeechRecognized;

        }

        private void ReEng_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            switch (e.Result.Text)
            {
                case "hello":
                    synth.SpeakAsync("\nhello sir, how are you?");
                    break;
                case "hi":
                    synth.SpeakAsync("\nwhat's up, sir?");
                    break;
                case "what is your name?":
                    synth.SpeakAsync("\nmy name is bongo");
                    break;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            reEng.RecognizeAsync(RecognizeMode.Multiple);

        }
    }
}

1 个答案:

答案 0 :(得分:0)

我认为内容类型规范(content_type)错误,您应该尝试:

handleSubmit(event) {
  console.log(this.state.value);
  fetch("http://192.168.0.133:8000/createrfq/",
  {
    method: "POST",
    cache: "no-cache",
    headers: {
      "Content-Type": "application/json"
    },
    body: JSON.stringify(this.state.value),
  })
  .then(response => response.json())

}