<?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 do I send data to HTTP Event Collector via Javascript with CORS in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-send-data-to-HTTP-Event-Collector-via-Javascript-with/m-p/454000#M29789</link>
    <description>&lt;P&gt;To avoid anyone experiencing any pain in trying to solve this problem here is what you need to do.  &lt;/P&gt;

&lt;P&gt;Under server.conf add the following lines&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[httpServer] 
crossOriginSharingPolicy = *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Under web.conf add the following lines&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[settings]
crossOriginSharingPolicy = *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Under inputs.conf add the following lines&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[http]
crossOriginSharingPolicy = *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then in javascript this will work&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var xhttp = new XMLHttpRequest();
                xhttp.open("POST", "https://yourservername.local/services/collector", true);
                xhttp.setRequestHeader("Authorization", "Splunk YOURHECCODE");
                xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                xhttp.send(JSON.stringify({
                  "event": "THE STRING YOU WANT TO SEND"
                  }));
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now these settings will work but you should think about crossOriginSharingPolicy before allowing everything.  The docs helped me in this one. &lt;/P&gt;

&lt;P&gt;Also, if you want to test this at home with a self signed certificate you can run ngrok to help you out with the following code&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;./ngrok http &lt;A href="https://127.0.0.1:8088" target="test_blank"&gt;https://127.0.0.1:8088&lt;/A&gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 20 Aug 2019 03:48:43 GMT</pubDate>
    <dc:creator>dperre_splunk</dc:creator>
    <dc:date>2019-08-20T03:48:43Z</dc:date>
    <item>
      <title>How do I send data to HTTP Event Collector via Javascript with CORS</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-send-data-to-HTTP-Event-Collector-via-Javascript-with/m-p/453999#M29788</link>
      <description>&lt;P&gt;Can anyone share some sample javascript code to send data over javascript to Splunk to avoid CORS (Cross Origin Resource Sharing).  I am thinking of embedding this code in an app.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2019 03:35:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-send-data-to-HTTP-Event-Collector-via-Javascript-with/m-p/453999#M29788</guid>
      <dc:creator>dperre_splunk</dc:creator>
      <dc:date>2019-08-20T03:35:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do I send data to HTTP Event Collector via Javascript with CORS</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-send-data-to-HTTP-Event-Collector-via-Javascript-with/m-p/454000#M29789</link>
      <description>&lt;P&gt;To avoid anyone experiencing any pain in trying to solve this problem here is what you need to do.  &lt;/P&gt;

&lt;P&gt;Under server.conf add the following lines&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[httpServer] 
crossOriginSharingPolicy = *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Under web.conf add the following lines&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[settings]
crossOriginSharingPolicy = *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Under inputs.conf add the following lines&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[http]
crossOriginSharingPolicy = *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then in javascript this will work&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var xhttp = new XMLHttpRequest();
                xhttp.open("POST", "https://yourservername.local/services/collector", true);
                xhttp.setRequestHeader("Authorization", "Splunk YOURHECCODE");
                xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                xhttp.send(JSON.stringify({
                  "event": "THE STRING YOU WANT TO SEND"
                  }));
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now these settings will work but you should think about crossOriginSharingPolicy before allowing everything.  The docs helped me in this one. &lt;/P&gt;

&lt;P&gt;Also, if you want to test this at home with a self signed certificate you can run ngrok to help you out with the following code&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;./ngrok http &lt;A href="https://127.0.0.1:8088" target="test_blank"&gt;https://127.0.0.1:8088&lt;/A&gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Aug 2019 03:48:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-send-data-to-HTTP-Event-Collector-via-Javascript-with/m-p/454000#M29789</guid>
      <dc:creator>dperre_splunk</dc:creator>
      <dc:date>2019-08-20T03:48:43Z</dc:date>
    </item>
  </channel>
</rss>

