dimanche 10 mai 2015

POST request - Long JSON string - request size too large / Endpoint not found

This is my first posting here, so please forgive if I break any rules. I have searched stackoverflow extensively but I wasn't able to find an answer for my problem.

Basically, I am trying to send a long JSON string from a Windows desktop application as the body of a POST request to a WCF service. By 'long' I mean that when I deserialize the string and export it as an XML file it takes up about 200 kB. However, I'm not getting anywhere with a short JSON string, either.

I tried using RestSharp but I keep getting an "Endpoint not found." error. When I try a method I found on StackOverflow or the default method from MSDN, I get an error saying: "Error 413: Request Entity Too Large." or, if I send a short JSON string, I get an "Error 400: Bad Request."

Here are the methods I used.

Restsharp: RestSharp simple complete example

(here I used the first answer with 141 votes) .NET: Simplest way to send POST with data and read response

http://ift.tt/1JWCUmm

I use VB.NET, but I'll gladly take an answer in C# as well. However, an answer in PHP or AJAX won't do me much good. I've already had a coworker implement this in AJAX and it works, but we're building the Windows desktop application in VB.NET and AJAX doesn't exactly translate word-for-word into VB.NET.

I would appreciate any help. Thanks in advance.

P.S. This is his AJAX code in the HTML file he sent me - and it works. I took out the URL for safety purposes, and I replaced the long JSON string with a simple one.

<!DOCTYPE HTML>
<html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->

<head>
<script src="http://ift.tt/1yCEpkO"></script> 
<script type="text/javascript">

function btn_click(){
//alert('btn');
var updatedData='[{"firstname": "Billy", "lastname": "Bob", "occupation": "cowboy"}]';
$.ajax({
        type: "POST",
        url:"<suppressed>",
        data: JSON.stringify(updatedData),
        contentType: "application/json; charset=utf-8?",
        dataType: "json",
        processData: true,
        success: function (data, status, jqXHR) {
                  alert("success…" + data);
        },
        error: function (xhr) {
               $('#msgText').text(xhr.responseText);
                     //alert(xhr.responseText);
        }
});

}
</script>
</head>
<body>
<input type="button" text="Click" Value="Click" onclick="btn_click()">
<label id="msgText"></label>
</body>

Aucun commentaire:

Enregistrer un commentaire