hatzisn Expert Licensed User Longtime User Aug 13, 2018 #1 Hi everyone, I am trying to post a pretty long json string (almost 2600 characters long) to asp.net back end and I get an error that the string was truncated and it is not full to be parsed. I googled it and I found some solutions at the internet which none of it worked. I tried it both in on-line IIS and local ASP.NET Development Center. To try it in local server I ran Fiddler and created a redirection in the Hosts from a virtual host called from the phone to the localhost as the local ASP.NET development server does not allow connections from other computers in order to test your code. I got the same errror. I thought Ok since it is this way and one cannot face its own destiny continueslly I will try it with a web service and post the string to the web service. Both in on-line IIS and local ASP.NET Development Server I get the 400 Bad Request response as I see in fiddler and in B4A just bad request. This is getting on my nurves. Any help will be highly appreciated. Thanks
Hi everyone, I am trying to post a pretty long json string (almost 2600 characters long) to asp.net back end and I get an error that the string was truncated and it is not full to be parsed. I googled it and I found some solutions at the internet which none of it worked. I tried it both in on-line IIS and local ASP.NET Development Center. To try it in local server I ran Fiddler and created a redirection in the Hosts from a virtual host called from the phone to the localhost as the local ASP.NET development server does not allow connections from other computers in order to test your code. I got the same errror. I thought Ok since it is this way and one cannot face its own destiny continueslly I will try it with a web service and post the string to the web service. Both in on-line IIS and local ASP.NET Development Server I get the 400 Bad Request response as I see in fiddler and in B4A just bad request. This is getting on my nurves. Any help will be highly appreciated. Thanks
MarkusR Well-Known Member Licensed User Longtime User Aug 13, 2018 #2 you send post as content type json? Code: Copy Job.PostString("http://www.abc/test" , data ) Job.GetRequest.SetContentType("application/json") 'need okhttp lib Upvote 0
you send post as content type json? Code: Copy Job.PostString("http://www.abc/test" , data ) Job.GetRequest.SetContentType("application/json") 'need okhttp lib
hatzisn Expert Licensed User Longtime User Aug 14, 2018 #3 Hi Markus, Here is the web service specifications (URL masked): POST /gwserv.asmx HTTP/1.1 Host: xxxxxxx.xxxxxx.gr Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "https://xxxxxxx.xxxxxx.gr/groupp" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <groupp xmlns="https://xxxxxxx.xxxxxx.gr/"> <json>string</json> </groupp> </soap:Body> </soap:Envelope> Here is the code that calls it: Code: Copy hj.PostString("https://xxxxxxx.xxxxxx.gr/gwserv.asmx", BuildRequest(CommonFunctions2.Template, sJson)) hj.GetRequest.SetContentType("text/xml; charset=utf-8") hj.GetRequest.SetHeader("SOAPAction", """https://xxxxxxx.xxxxxx.gr/groupp""") The CommonFunctions2.Template returns the lines seen green above and the BuildRequest function replaces the blue "string" seen above with a very long JSon (greater than 2500 characters long). The answer was 400 bad request. Upvote 0
Hi Markus, Here is the web service specifications (URL masked): POST /gwserv.asmx HTTP/1.1 Host: xxxxxxx.xxxxxx.gr Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "https://xxxxxxx.xxxxxx.gr/groupp" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <groupp xmlns="https://xxxxxxx.xxxxxx.gr/"> <json>string</json> </groupp> </soap:Body> </soap:Envelope> Here is the code that calls it: Code: Copy hj.PostString("https://xxxxxxx.xxxxxx.gr/gwserv.asmx", BuildRequest(CommonFunctions2.Template, sJson)) hj.GetRequest.SetContentType("text/xml; charset=utf-8") hj.GetRequest.SetHeader("SOAPAction", """https://xxxxxxx.xxxxxx.gr/groupp""") The CommonFunctions2.Template returns the lines seen green above and the BuildRequest function replaces the blue "string" seen above with a very long JSon (greater than 2500 characters long). The answer was 400 bad request.
OliverA Expert Licensed User Longtime User Aug 14, 2018 #4 So a short string works and a long string gives you a 400 error code? Upvote 0
Jorge M A Well-Known Member Licensed User Longtime User Aug 15, 2018 #5 Maybe your "sJson" variable contains characters that needs to be escaped. Take a look this @Erel's code snippet: https://www.b4x.com/android/forum/threads/escapexml-code-snippet.35720/ Also you can check @Erel's video about WebServices from 12:57, if you are using smart literals to build your json string. Last edited: Aug 15, 2018 Upvote 0
Maybe your "sJson" variable contains characters that needs to be escaped. Take a look this @Erel's code snippet: https://www.b4x.com/android/forum/threads/escapexml-code-snippet.35720/ Also you can check @Erel's video about WebServices from 12:57, if you are using smart literals to build your json string.
KMatle Expert Licensed User Longtime User Aug 15, 2018 #6 I always convert JSON structures to a Base64 string and back. Upvote 0