Angular 2 PUT 内容 uri/list 内容类型(多元素)

Angular 2 PUT content with uri/list content type(multiple elements)

如何在 Angular 2 打字稿中发送以下内容?

要发送多个 URI,我们必须用换行符将它们分开:

curl -i -X PUT -H "Content-Type:text/uri-list" --data-binary @uris.txt http://localhost:8080/authors/1/books

uris.txt 文件包含书籍的 URI,每一个单独一行:

http://localhost:8080/books/1 http://localhost:8080/books/2

我知道如何发送 PUT htt 请求,但没有找到在 PUT 请求中发送多个元素的解决方案!

我无法制作这样的内容: http://localhost:8080/books/1 http://localhost:8080/books/2

Typescript 始终将“”放入字符串中,我在服务器端遇到错误。

我可以这样发一份:

 return this.http
    .put(`${this.apiUrl + this.quizesUrl}/${quiz.id}${this.questionsUrl}`
        , `${this.apiUrl + this.questionsUrl}/4`, QuizesService.OPTIONS_URI_LIST) // ...using put request
    .map(this.handleSingleResponse) // ...and calling .json() on the response to return data
    .catch(this.handleError) // ...errors if any
    .finally(() => {
      console.log('After updateQuestion request...');
    })

;

如何从集合中发送多个?

saveQuizQuestionAssignment(quiz: Quiz) {
  console.log(`${this.apiUrl + this.quizesUrl}/${quiz.id}${this.questionsUrl}`);
  console.log(this.createQuizQuestionRequest(quiz));
  return this.http
        .put(`${this.apiUrl + this.quizesUrl}/${quiz.id}${this.questionsUrl}`
            , this.createQuizQuestionRequest(quiz), QuizesService.OPTIONS_URI_LIST) 
        .map(this.handleSingleResponse) 
        .catch(this.handleError) 
        .finally(() => {
          console.log('After updateQuestion request...');
        }); 
}

createQuizQuestionRequest(quiz: Quiz) {
  var putRequestLine = '';
  quiz.questions.forEach(question => {    
    putRequestLine += `${this.apiUrl + this.questionsUrl + '/' + question.id}`+'\n';       
  });
  return putRequestLine;
}

我找到了非常简单的解决方案。 /当你累了很难找到最简单的东西/

'createQuizQuestionRequest' 函数追加 uri-list 内容并被后端接受。然后请求将更新关系 table(quiz_question).

中的 quiz-question 赋值

所以代码等同于邮递员发送的以下请求: