<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to use esri.request to post JSON? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183770#M17072</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes that's the idea, but only for more complex content parameters that are also JSON objects. &amp;nbsp;Why not try the request with a jQuery Ajax or standard XMLHttpRequest instead?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 13 Jun 2017 05:51:52 GMT</pubDate>
    <dc:creator>FC_Basson</dc:creator>
    <dc:date>2017-06-13T05:51:52Z</dc:date>
    <item>
      <title>How to use esri.request to post JSON?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183765#M17067</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have been using the esri.request to make get calls for a while and it's worked great:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;request = Request({url: url, handleAs: 'json'});&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Now I have a requirement to be able to post JSON data and get a similar response. From the API reference I thought it would be as simple as:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;request = Request({url: url, handleAs: 'json', callbackParamName: 'callback', content: params}, {usePost: 'true'});&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;But I was getting a 415 error from the REST endpoint I was hitting.&lt;/P&gt;&lt;P&gt;I looked at the developer tools, Network section, and I saw that under Params, the payload was of type Form data. I think it needs to be JSON format. I looked under Headers and Content-Type is "application/x-www-form-urlencoded".&lt;/P&gt;&lt;P&gt;So I found the setRequestPreCallback function and started using that to set the headers["Content-Type"] = "application/json". That seemed to work because I can see Content-Type is now "application/json". However, my 415 error changed to a 400 error. If I look under Params it is not type JSON like I expect. It just says Request payload and the data looks like a string with = and &amp;amp; instead of a JSON format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there something else you have to do to make the data post as JSON?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jun 2017 00:06:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183765#M17067</guid>
      <dc:creator>NavanJohnson</dc:creator>
      <dc:date>2017-06-08T00:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to use esri.request to post JSON?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183766#M17068</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try { ..., content:JSON.stringify(params), ... }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It may be interpreting your params as &lt;A href="https://developer.mozilla.org/en-US/docs/Web/API/FormData"&gt;FormData&lt;/A&gt;&amp;nbsp;or something along those lines.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jun 2017 00:11:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183766#M17068</guid>
      <dc:creator>ThomasSolow</dc:creator>
      <dc:date>2017-06-08T00:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to use esri.request to post JSON?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183767#M17069</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yeah, I did try that, and under Params it still says Request payload and the value looks like:&lt;/P&gt;&lt;P&gt;0=%7B&amp;amp;1=%22&amp;amp;2=s&amp;amp;3=y&amp;amp;4=s&amp;amp;5=_&amp;amp;6=a&amp;amp;7=s&amp;amp;8....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I even tried to just hard code the content like:&lt;/P&gt;&lt;P&gt;request = Request({url: url, handleAs: 'json', callbackParamName: 'callback', content: {username: "test", role: "user"}}, {usePost: 'true'});&lt;/P&gt;&lt;P&gt;And I still get a Request payload that looks like:&lt;/P&gt;&lt;P&gt;username=test&amp;amp;role=user&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jun 2017 00:44:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183767#M17069</guid>
      <dc:creator>NavanJohnson</dc:creator>
      <dc:date>2017-06-08T00:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to use esri.request to post JSON?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183768#M17070</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried&amp;nbsp;&lt;SPAN style="background-color: #ffffff;"&gt;JSON.stringify on the individual JSON-format parameters in the request content? &amp;nbsp;And also throw in a&amp;nbsp;f: "json" in the content.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Jun 2017 07:40:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183768#M17070</guid>
      <dc:creator>FC_Basson</dc:creator>
      <dc:date>2017-06-09T07:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to use esri.request to post JSON?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183769#M17071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you mean like this?&lt;/P&gt;&lt;P&gt;request = Request({url: url, handleAs: 'json', callbackParamName: 'callback', content: {f: "json", username: &lt;SPAN style="background-color: #ffffff;"&gt;JSON.stringify&lt;/SPAN&gt;("test"), role: &lt;SPAN style="background-color: #ffffff;"&gt;JSON.stringify(&lt;/SPAN&gt;"user")}}, {usePost: 'true'});&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That creates a Request payload of:&lt;/P&gt;&lt;P&gt;f=json&amp;amp;username=%22test%22&amp;amp;role=%22user%22&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It still doesn't look like JSON and still gives status 400.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jun 2017 21:52:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183769#M17071</guid>
      <dc:creator>NavanJohnson</dc:creator>
      <dc:date>2017-06-12T21:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to use esri.request to post JSON?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183770#M17072</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes that's the idea, but only for more complex content parameters that are also JSON objects. &amp;nbsp;Why not try the request with a jQuery Ajax or standard XMLHttpRequest instead?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jun 2017 05:51:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183770#M17072</guid>
      <dc:creator>FC_Basson</dc:creator>
      <dc:date>2017-06-13T05:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to use esri.request to post JSON?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183771#M17073</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yeah, that's what I am doing for now. The $.ajax works as expected. I just wanted to use pure esri if I could. It seems like something that is supposed to work and I am just missing something. Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jun 2017 15:58:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183771#M17073</guid>
      <dc:creator>NavanJohnson</dc:creator>
      <dc:date>2017-06-13T15:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to use esri.request to post JSON?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183772#M17074</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In the Network tab, can you&amp;nbsp;see if the request is being made as GET or POST? &amp;nbsp;If it still uses GET, one suggestion is to try using a boolean instead of a string for the 'usePost' parameter. &amp;nbsp;It also helps if you have a JSBin or similar so we can see the code and issue in action.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="language-javascript line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;usePost&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;true&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jun 2017 16:54:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183772#M17074</guid>
      <dc:creator>JohnGrayson</dc:creator>
      <dc:date>2017-06-13T16:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to use esri.request to post JSON?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183773#M17075</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would also like to see how the esri.request compares to the jQuery Ajax request.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Jun 2017 08:54:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183773#M17075</guid>
      <dc:creator>FC_Basson</dc:creator>
      <dc:date>2017-06-14T08:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to use esri.request to post JSON?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183774#M17076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Look at the code under the folder named "editors" of the ESRI's geoprocessing widget. You will see how they handle post with url or files (csv, shapefiles)....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jun 2017 15:50:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-use-esri-request-to-post-json/m-p/183774#M17076</guid>
      <dc:creator>LefterisKoumis</dc:creator>
      <dc:date>2017-06-27T15:50:41Z</dc:date>
    </item>
  </channel>
</rss>

