473,224 Members | 1,685 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

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.   }
May 10 '22 #1
1 7910
Dormilich
8,658 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.
May 11 '22 #2

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

Similar topics

3
by: Patrick Hoffmann | last post by:
hi folx, today I had "multithreading" trouble with the following code (MS VC++6/optimized compiling): --------------------------- class myclass { static int s_nNext; public:
5
by: FireHead | last post by:
Hello All, Its hard to explain but here it goes: char &free_malloc(char* object_copy){ Here ------------------------------------------------------------------ object_copy is parametre were...
3
by: quiz123 | last post by:
Hi folks, I have a problem. my function call is void Rotate_n(int array, int arraySize,int n); //precondition: arraysize>=1 && n>=0 && n<=arraySize //post condition: Values in the arrary are...
1
by: Jd | last post by:
Hi I have the following situation.. Have a worker thread, that does the "work" given to it. While doing work, some of the objects use thread local storage for storing that requires explicit close....
3
by: Atmapuri | last post by:
Hi! My dll uses Thread Local Storage because of Open MP. Is there any workaround on how this dll, can be called from ..NET? What changes would be neccessary? Will that be addressed in VS2008?...
1
by: TheCornjerker | last post by:
I'm looking for two mechanisms for a hosted web application. One is to allow users to take notes or make comments about a web page and have the information stored locally on their computer. The...
0
by: =?UTF-8?B?Q2hyaXN0aWFuIFLDtnNzZWw=?= | last post by:
An object of struct TLS should be thread-local: struct Foo {}; struct TLS { Foo* a; bool b; }; __declspec(thread) TLS MyTLS;
4
by: mopufo | last post by:
My website has a back-end admin area used by volunteers to add content to the Db which contains over 60 table. When each volunteer logs into the Admin area I store their Username and access lever in...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.