Attempting to make a slightly bigger than usual AXIOS.post request to a .NET Web API

When attempting to perform an AXIOS.post in a Vue.JS application, the process fails when exceeding about 1500 characters. Instead of reaching the Web API, it goes directly to the error area. Typically, this function calls a .Net Web API that generates a MS Word Document and returns it to the user.

 let pm = "1234567890,"

Create loop to add pm = pm + pm '200 times

let updatedData = {        
      memberID: 12345,
      pmids: pm             
  };

  axios({
    method: "post",
    url:         
     "http://localhost:54269/api/DataTable/PostValue",
    params: {
      value: JSON.stringify(updatedData)        
    },  
    responseType: 'blob' , 
    maxContentLength: Infinity,
    maxBodyLength: Infinity,
    headers: {
      'content-type': 'application/json',         
      'Accept': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
 }
  }).then(response =>{ 
    const url = window.URL.createObjectURL(new Blob([response.data]));
    const link = document.createElement('a');
    link.href = url;
    link.setAttribute('download', 'DataTable4_.docx');
    document.body.appendChild(link);
    link.click();
   }) 
  .catch(err => { 
      if( err.response ){
      console.log(err.response.data); 
   }
     if( err.message ){
      console.log("message:  " + err.message); 
   }   
  });      

} ,

Once PM exceeds 1500 characters, I encounter an error

 POST http://localhost:54269/api/DataTable/PostValue?value=%7B%22memberID%22:12345,%22pmids%22:%2212345,23456,45678%22%7D 500 (Internal Server Error)
dispatchXhrRequest @ xhr.js?e38e:177
xhrAdapter @ xhr.js?e38e:13
dispatchRequest @ dispatchRequest.js?c09c:52
Promise.then (async)
request @ Axios.js?108a:61
wrap @ bind.js?784f:9
saveSwitchValue @ reporterAPI_Unique_PI.vue?5e84:382
create_word_doc_post @ reporterAPI_Unique_PI.vue?5e84:451
toolbarClick @ reporterAPI_Unique_PI.vue?5e84:816
Observer.notify @ observer.js?e8e3:99
Base.trigger @ base.js?3f78:181
GridComponent.trigger @ grid.component.js?9a24:85
Toolbar.toolbarClickHandler @ toolbar.js?3c15:337
Observer.notify @ observer.js?e8e3:99
Base.trigger @ base.js?3f78:181
Toolbar.clickHandler @ toolbar.js?4b00:573
reporterAPI_Unique_PI.vue?5e84:409 
Blob {size: 1151, type: 'application/json'} size: 1151 type: "application/json" [[Prototype]]: Blob arrayBuffer: ƒ arrayBuffer() size: (...) slice: ƒ slice() stream: ƒ stream() text: ƒ text() type: (...) constructor: ƒ Blob() Symbol(Symbol.toStringTag): "Blob" get size: ƒ size() get type: ƒ type() [[Prototype]]: Object

I expect to be able to utilize JSON.stringify to send a considerable amount of data to a server without issues. I am not referring to uploading large amounts of data, just moderate sizes. If there are expert training resources available, I am eager to learn. Existing tutorials on platforms like Udemy and YouTube predominantly focus on small-scale examples. Additionally, I have verified and adjusted the Maximum allowed content length on my local IIS server to handle larger requests.

If interested:

<System.Web.Http.HttpPost> <System.Web.Http.Route("api/DataTable/PostValue")> Public Function PostValue(ByVal value As String) As String 'HttpResponseMessage

String for testing

Answer №1

The reason behind your problem is that you are attempting to send that extensive JSON object as a query parameter. IIS imposes a limit of 2048 bytes on URL length.

For large data objects, it is recommended to pass them within the request body using the data property. Please refer to the Axios documentation for further details.

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

Methods for hiding and showing elements within an ngFor iteration?

I am working on an ngFor loop to display content in a single line, with the option to expand the card when clicked. The goal is to only show the first three items initially and hide the rest until the "show more" button is clicked. let fruits = [apple, o ...

Trigger notifications exclusively for specific hyperlink texts that are selected

I'm facing an issue where I need to notify the user when a specific link text for a hyperlink is clicked. The code provided here showcases the problem I am currently encountering. At the moment, the alert triggers whenever any link text is clicked, ra ...

Suspend operation to delay for ajax call within a websocket

Looking for a solution regarding a WebSocket that updates a messaged list when receiving a message. Currently using a fetch request to retrieve data from the server in order to populate the messaged list. However, facing an issue as the code needs to pau ...

What is the best method for efficiently loading SVG icons on an HTML page without redundancy? / Is utilizing <use href> recommended?

My struggle with implementing icons in Angular While working on a new Angular project, I've encountered challenges with my current SVG-icon implementation method from a previous project (@ngneat/svg-icon). The process involves organizing SVG files in ...

How can I implement dynamic loading on a button click using Ajax?

Is it possible to create a loading button with a dynamic timer? Take a look at the code snippet below: var $this = $(this); $this.button('loading'); setTimeout(function() { $this.button('reset&apo ...

Instructions for implementing onclick functionality on an iframe element

Is it possible to use the onclick event in an iframe tag to call a JavaScript function? I have integrated a Facebook like button on my website using an iframe code. When a user clicks on the like button, I would like them to be redirected to a 'thank ...

Combining the power of jQuery, PHP, JavaScript, and the popular WordPress platform, let's unlock

After going through numerous attempts to find answers for similar issues, I'm unable to get any of the suggested solutions to work. My WordPress site requires a plugin that utilizes jQuery. The main file for my plugin is located at wp-content/plugins ...

Postman Guide: Mastering the Evaluation of JSON Arrays

One of the features in Postman allows users to save a specific field from the response body as a variable and then utilize that variable in a subsequent call. For instance, after my initial call to the web service, the response body contains: [ { "id" ...

Using Javascript and JQuery to create an alert that pops up upon loading the page is not effective

I am having trouble making an alert show up when my website loads. The Javascript code is functional when directly included in the HTML, but once I move it to a separate file named script.js and link it, nothing happens. Can someone please help me identify ...

javascript accessing an external variable inside ajax function

I have implemented dajaxice to fetch a json attribute that I want to make global. However, I am facing an issue where my global variable is always showing up as "undefined": var recent_id; $(function(){ recent_id = Dajaxice.ticker.get_home_timeline(ge ...

How can I adjust the width of a handle/thumb for NoUiSlider?

Looking to adjust the width of a NoUiSlider using CSS: .noUi-horizontal .noUi-handle { width:8px; height:25px; left: 0px; top: -8px; border: 0px solid #000000; border-radius: 0px; background: #000; cursor: default; box- ...

The debate between using backticks and colons in TypeORM queries

Lately, I've been crafting queries utilizing backticks const firstUser = await connection .getRepository(User) .createQueryBuilder("user") .where(`user.id = '${id}'`) .getOne(); However, in the typeorm documentatio ...

Invoke an AngularJS directive from a controller when clicked

Hey there! I'm currently utilizing the tg-dynamic-directive to loop through a JSON file and display the tree structure shown in the attached image. https://i.sstatic.net/Ph6Cs.png One major issue I'm facing is performance degradation when the " ...

Having trouble with jQuery live clock freezing your browser?

I recently created a clock script and utilized setInterval to keep it running smoothly. However, I've encountered an issue where my browser freezes after a short period of time. Unfortunately, I'm unsure how to troubleshoot this problem on my own ...

Exploring jQuery's parent selector for traversing the DOM

I am currently working with an array that inserts articles into my website. I have a specific requirement where, upon clicking the title (h3), I need to display more information based on the article's index. To achieve this, I believe I should travers ...

JavaScript: Organizing values based on their case sensitivity

Imagine a scenario where we have models ABC23x, ABC23X & abc23X all referring to the same model. These model names are retrieved from API endpoints. Now the UI has two tasks: Display only one model name (ABC23X) When calling the REST API, we need to sen ...

What could be causing the server to return an empty response to an ajax HTTP POST request?

Attempting to make a POST request using ajax in the following manner: $.ajax({ type: "POST", url: 'http://192.168.1.140/', data: "{}", dataType: "json", ...

Issue encountered with the style parameter in print-js when attempting to print from a Vue.js component

While browsing the print-js documentation, I came across a feature that allows us to pass style as a string to the printJS function. However, when attempting to apply this style, I encountered an error preventing the print action: The error I'm facin ...

What is the best way to find the longest element with the same class name using jQuery?

How can I dynamically find elements with the same length of class names? var className = $('.floor-4').attr('class').split(' ')[1]; var classLength = $('.' + className).length; Here is the HTML code: <div id="d ...

Unexpected Results when Sorting Objects by Value

When attempting to organize 2 objects based on the value of first_name, one in ascending alphabetical order and the other in descending order, both end up being sorted in descending order. What could be the mistake in this code? The objective is to rearr ...