Error when sending JSON to Web API if too long

Viewed 57

I'm have problems sending a JSON object to a .NET Web API. I have multi array that I convert into JSON and send to the web service. The total length of the object is just over 50,000 characters. If I do a slice on the array everything is fine. It does not matter what 2 items I send as long as it's less that 2500 characters.

   let value = JSON.stringify(this.excelData.results.slice(2, 2));
   axios({
   method: 'post',      
   url: 'http://adminapiSystem.com/api/saveJSONData',
   params: {          
     value: value
    }    
   })
  .then((res) => {
    console.log('Saved')
  }) 
  .catch(err => {
      console.log(err)
  
  } )

I was under the impression that the max length was 2097152 or 4 meg

my web service is

     Public Function PostValue(ByVal value As String) As String
        Dim ret As String = SendDataSQL(value)
        Return ret
    End Function

and the error is

        xhr.js?b50d:177 POST http://xxxxx/api/saveJSONData?value=    [%7B%22Status%22:%22Active%22,%22DBID%22:%22SB%22,%22ID%22:11691,%22Search%22:null,%22Year_Start%22:2015,%22Year_End%22:3000,%22Enrolled%22:null,%22WithDrawn%22:null,%22Last_Name%22:%22Baer%22,%22First_Name%22:%22Lea%22,%22MI%22:null,%22Suffix%22:null,%22PubMed_ForeName%22:null,%22PubMed_Initials%22:null,%22Email%22:%22Lea.Baer%40stonybrookmedicine.edu%22,%22ORCID%22:null,%22Membership_Type%22:%22Affiliate%22,%22ProgramName%22:%22Non-Programmatically+aligned%22,%22Program_Code%22:%22ZY%22,%22Program_Roles%22:null,%22Search_Term%22:null,%22PMID_New%22:null,%22Harvard_Search_PMIDs%22:null,%22PMID_Current%22:null,%22PMID_Exclude%22:null,%22Affiliations%22:%22Stony+Brook%22,%22Authoring_Names%22:null,%22Basic_Search_String%22:null,%22Send_Email%22:null,%22Custom_Search_String%22:null,%22Academic_Title%22:null,%22Department%22:%22Medicine%22%7D,%7B%22Status%22:%22Active%22,%22DBID%22:%22SB++++++++%22,%22ID%22:11683,%22Search%22:null,%22Year_Start%22:2015,%22Year_End%22:3000,%22Enrolled%22:null,%22WithDrawn%22:null,%22Last_Name%22:%22Bahou%22,%22First_Name%22:%22Wadie%22,%22MI%22:%22F%22,%22Suffix%22:null,%22PubMed_ForeName%22:null,%22PubMed_Initials%22:null,%22Email%22:%22Wadie.bahou%40stonybrookmedicine.edu%22,%22ORCID%22:null,%22Membership_Type%22:%22Affiliate%22,%22ProgramName%22:%22Non-Programmatically+aligned%22,%22Program_Code%22:%22ZY%22,%22Program_Roles%22:null,%22Search_Term%22:null,%22PMID_New%22:null,%22Harvard_Search_PMIDs%22:null,%22PMID_Current%22:null,%22PMID_Exclude%22:null,%22Affiliations%22:%22Stony+Brook%22,%22Authoring_Names%22:null,%22Basic_Search_String%22:null,%22Send_Email%22:null,%22Custom_Search_String%22:null,%22Academic_Title%22:null,%22Department%22:%22Medicine%22%7D,%7B%22Status%22:%22Active%22,%22DBID%22:%22SB++++++++%22,%22ID%22:11685,%22Search%22:null,%22Year_Start%22:2015,%22Year_End%22:3000,%22Enrolled%22:null,%22WithDrawn%22:null,%22Last_Name%22:%22Bakoulis%22,%22First_Name%22:%22Anastasia%22,%22MI%22:null,%22Suffix%22:null,%22PubMed_ForeName%22:null,%22PubMed_Initials%22:null,%22Email%22:%22Anastasia.Bakoulis%40stonybrookmedicine.edu%22,%22ORCID%22:null,%22Membership_Type%22:%22Affiliate%22,%22ProgramName%22:%22Non-Programmatically+aligned%22,%22Program_Code%22:%22ZY%22,%22Program_Roles%22:null,%22Search_Term%22:null,%22PMID_New%22:null,%22Harvard_Search_PMIDs%22:null,%22PMID_Current%22:null,%22PMID_Exclude%22:null,%22Affiliations%22:%22Stony+Brook%22,%22Authoring_Names%22:null,%22Basic_Search_String%22:null,%22Send_Email%22:null,%22Custom_Search_String%22:null,%22Academic_Title%22:null,%22Department%22:%22Surgery%22%7D] 404 (Not Found)
dispatchXhrRequest @ xhr.js?b50d:177
xhrAdapter @ xhr.js?b50d:13
dispatchRequest @ dispatchRequest.js?5270:52
Promise.then (async)
request @ Axios.js?0a06:61
wrap @ bind.js?1d2b:9
saveAllData @ publication_report.vue?02c8:145
invokeWithErrorHandling @ vue.runtime.esm.js?2b0e:1854
invoker @ vue.runtime.esm.js?2b0e:2179
invokeWithErrorHandling @ vue.runtime.esm.js?2b0e:1854
Vue.$emit @ vue.runtime.esm.js?2b0e:3888
click @ QBtn.js?9c40:101
invokeWithErrorHandling @ vue.runtime.esm.js?2b0e:1854
invoker @ vue.runtime.esm.js?2b0e:2179
original._wrapper @ vue.runtime.esm.js?2b0e:6917
publication_report.vue?02c8:156 Error: Request failed with status code 404
    at createError (createError.js?2d83:16)
    at settle (settle.js?467f:17)
    at XMLHttpRequest.handleLoad (xhr.js?b50d:62)

My web config has

       <scripting>
  <webServices>
    <jsonSerialization maxJsonLength="2147483644" />
  </webServices>
     </scripting>

and

  <system.web>
  <compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1" maxUrlLength="10240" relaxedUrlToFileSystemMapping="true" />
<customErrors mode="Off" />
 </system.web>

One last item-- I'm using HostBuddy as my hosting service

1 Answers

You are sending the POST request and the data are in the URL.

The GET maximum length is 2,048 characters and you will not be able to send more. It's an HTTP limit.

What you can do is to send this data via the POST method in BODY, which does not have limits.

This Axios code should work for you:

axios({
  method: 'post',
  url: 'http://adminapiSystem.com/api/saveJSONData',
  data: {
    value: value
  }
});
Related