Click here to Skip to main content
15,442,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to POST my local storage to an API, but everytime I do it, I get a status: 400. Title of error says '"One or more validation errors occurred."'

I must be doing this wrong. I'm trying to loop through all the key value pairs and then send that via a POST.

What I have tried:

public postInfo() {
    for (let i = 0; i < localStorage.length; i++) {
      const key = localStorage.key(i);

    const headerDict = {
      'Content-Type': 'application/json',
      'Accept': 'application/json',
      'Access-Control-Allow-Headers': 'Content-Type',

    const requestOptions = {
      headers: new HttpHeaders(headerDict),
    };, key, requestOptions).subscribe(data => {

Also here is how I'm saving my local storage:

addToCart(product: Product) {
    var sendJson = JSON.stringify(product.productID);
    var jsonData = JSON.stringify(product.productName)
    localStorage.setItem(sendJson, jsonData);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900