470,632 Members | 1,477 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,632 developers. It's quick & easy.

POST local storage - angular

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.

Expand|Select|Wrap|Line Numbers
  1.   public postInfo() {
  2.     for (let i = 0; i < localStorage.length; i++) {
  3.       const key = localStorage.key(i);
  4.  
  5.     const headerDict = {
  6.       'Content-Type': 'application/json',
  7.       'Accept': 'application/json',
  8.       'Access-Control-Allow-Headers': 'Content-Type',
  9.     }
  10.  
  11.     const requestOptions = {
  12.       headers: new HttpHeaders(headerDict),
  13.     };
  14.  
  15.       this.http.post(this.url, key, requestOptions).subscribe(data => {
  16.         console.log(data);
  17.         });
  18.       }
  19.  
  20.   }
Also here is how I'm saving my local storage:

Expand|Select|Wrap|Line Numbers
  1. addToCart(product: Product) {
  2.     var sendJson = JSON.stringify(product.productID);
  3.     var jsonData = JSON.stringify(product.productName)
  4.     localStorage.setItem(sendJson, jsonData);
  5.   }
2 Weeks Ago #1
1 6000
Dormilich
8,656 Expert Mod 8TB
There are two things you can do: check if the response specifies the errors, and if not, look at the request (in the dev tools) and manually check whether the request conforms to the API's requirements.
2 Weeks Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by FireHead | last post: by
1 post views Thread by Jd | last post: by
3 posts views Thread by Atmapuri | last post: by
1 post views Thread by TheCornjerker | last post: by
reply views Thread by =?UTF-8?B?Q2hyaXN0aWFuIFLDtnNzZWw=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.