ServiceStack request without the use of quotation marks in the JSON body

Why do quotes appear in my request body in Fiddler, but not in my ServiceStack request field?

POST http://10.255.1.180:8087/testvariables/new/ HTTP/1.1
Host: 10.255.1.180:8087
Connection: keep-alive
Content-Length: 162
Origin: http://10.255.1.180:8087
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36
content-type: application/json;charset=UTF-8
Accept: */*
Referer: http://10.255.1.180:8087/certFields
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,fr;q=0.6

{"Field":{"Id":67,"Name":"Brightness Reversion","Header":"Brightness Reversion.","Format":"#0.0","Uom":"%","Precision":0,"MapId":8083,"IsMappedToCustomer":false}}

Calling from Typescript/Angular2

let body = JSON.stringify(certField);    
let headers = new Headers({ 'Content-Type': 'application/json;charset=utf-8' });

let requestoptions: RequestOptions = new RequestOptions({
            method: RequestMethod.Post,
            url: this._certFieldsUrl + 'new/',
            headers: headers,
            body: '{"Field":'+body+'}'
        })
return this._http.request(new Request(requestoptions))
            .toPromise()
            .then(function (response) {
                return response.json() as CertFieldSaveResponse;
            })
            .catch(this.handleError);

Request Class

public class CertFieldUpdateRequest : IReturn<TestVariableResponse>
    {
        public string Field { get; set; }

    }

POST Method

    public object Post(CertFieldUpdateRequest request)
    {
                log.Debug(request.Field);
       ....
    }

Within the service, in the POST method, the value of the request.Field is:

    {Id:67,Name:Brightness Reversion,Header:Brightness Reversion.,Format:#0.0,Uom:%,Precision:0,MapId:8083,IsMappedToCustomer:false}

Answer №1

One reason for this issue could be that your body is actually a complete JSON object and not just a string inside a JSON object. To address this, you can either:

   let requestOptions: RequestOptions = new RequestOptions({
        method: RequestMethod.Post,
        url: this._certFieldsUrl + 'new/',
        headers: headers,
        body: {Field : JSON.stringify(body)}
    })

Another approach is to add properties to your code class:

   public class CertFieldUpdateRequest : IReturn<TestVariableResponse>
   {
    public Field Field { get; set; }

   }

   public class Field
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Header { get; set; }
        public string Format { get; set; }
        ///etc...
    }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Receive notification indicating that the function is of void type

As a newcomer to angular, I am currently in the process of setting up my authorization module for an ionic project I am developing. I have made significant progress, but I have encountered an issue with the 'auth' service that I created. Within ...

Creating a Typescript mixin function that accepts a generic type from the main class

I am working with the code snippet shown below: // Types found on https://stackoverflow.com/a/55468194 type Constructor<T = {}> = new (...args: any[]) => T; /* turns A | B | C into A & B & C */ type UnionToIntersection<U> = (U extend ...

Troubleshooting Angular 2 RC5: detectChanges function not functioning as expected

Currently, I am working on developing a login form component that has the following interface: <login-form onlogin="submit()"></login-form> Here is the testing code for this component: it("Ensuring credentials are passed correctly out of t ...

Associate the generic operator <T> with a FunctionConstructor

In my TS function, I deserialize JSON into a specific type/object by providing it with a constructor function of that type which reconstructs the object from JSON. Here is how it looks like: export function deserializeJSON<T>(JSONString: string, ty ...

Problems encountered with operating the Bootstrap burger menu

After following the Bootstrap navbar documentation and implementing the code in my bs-navbar.component.html file, I encountered an issue with the hamburger menu. Despite everything being set up correctly, clicking on the hamburger icon did not display the ...

Troubleshooting issues with implementing Playwright in Angular framework

I want to automate my Playwright end-to-end tests that run during GitHub actions. The Angular App being tested is very small and simple (running version 16). Here is my main deployment.yml file: name: Deployment on: push: branches: - main w ...

Highcharts still unable to display series data despite successful decoding efforts

After receiving JSON decoded data from the server and using $.parseJSON to decode it, I am assigning it to the series in Highcharts. Although there are no console errors, the chart refuses to display. Below is the code snippet: <!DOCTYPE html> < ...

The argument provided is of type 'string | null' which cannot be assigned to a parameter expecting only 'string' type. The value of 'null' is not compatible with the type 'string' in Angular 12

When trying to parse the stored session data using JSON.parse(sessionStorage.getItem('owner')), we may encounter an error stating: Argument of type 'string | null' is not assignable to parameter of type 'string'. This is becau ...

Building an Angular 4 universal application using @angular/cli and integrating third-party libraries/components for compilation

While attempting to incorporate server side rendering using angular universal, I referenced a post on implementing an angular-4-universal-app-with-angular-cli and also looked at the cli-universal-demo project. However, I ran into the following issue: Upon ...

Encountered an error while loading resource: net::ERR_CONNECTION_REFUSED in Nodejs

I am currently working on a form in my angular 6 app with nodejs, utilizing nodemailer for sending emails. Unfortunately, I am encountering an error that reads: Failed to load resource: net::ERR_CONNECTION_REFUSED : :3000/contact/send:1 Below is the form ...

What could be causing this error for my NPM module in a .NET Core project using Typescript?

My Typescript configuration seems to be causing some issues, even though everything works fine without TS. Could the problem lie in my .d.ts file? And do I really need it for webpack? I have a basic NPM module: index.js: var MyMathTS = function(a, b){ ...

Observing a class getter within Vue.js

The issue at hand I am facing a challenge in ensuring my page automatically updates when new data is available. I am using Ionic, and have a page that displays all the items collected by the user in a visually appealing manner using an ion-grid. To achiev ...

Encountering a problem with the starting seed for the Users database

I encountered an error while trying to create the initial seed. I'm able to seed the role collection successfully but facing issues with seeding the users collection. Can someone assist me in understanding why this error is occurring and how I can res ...

"Unleash the Power of Go HTTP Server for React, Angular, and

Recently, I developed a small HTTP Server in GO specifically for static files: func wrapHandler(h http.Handler) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { h.ServeHTTP(srw, r) log.Printf("GET %s", r.RequestU ...

What makes a single number a valid JSON format?

$.parseJSON("1") results in 1 being returned. It is surprising that this works without throwing an error because it does not follow the standard JSON format like this: { "firstName": "John" } How is it possible for 1 to be parsed correctly? Is there ...

Unlocking the Power of Angular's Default Input Required Validation

Just aiming to utilize the default required validation functionality in HTML. This is the code I've implemented: <form (ngSubmit)="submit()"> <div class="login-container"> <ion-item> <ion-input ...

Indicate the type of method without transforming it into a property

If I have a method in my application that delegates its functionality to an external library method, and I know the type for that external method (e.g. LibDoStuffMethodType), how can I specify the type for my method MyApp.doStuff() without making it a prop ...

Issue with node.js fnoc module causing error - likely a simple fix

Having some trouble with integrating node-fnoc into my project. I've set up a directory with a basic package.json file, as well as a /config/ directory within it containing a simple JSON file. I'm attempting to follow the example provided by the ...

Building an ExtJS grid layout using JSON information

I want to clarify that my question is not about populating a grid with records from a json file. Rather, I am looking to create the actual columns of the grid using json. I want to save all the attributes of the columns, such as width, locked, and visibi ...

Obtain the position and text string of the highlighted text

I am currently involved in a project using angular 5. The user will be able to select (highlight) text within a specific container, and I am attempting to retrieve the position of the selected text as well as the actual string itself. I want to display a s ...