<?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: Connection Reset - while connecting with token in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Getting-401-while-connecting-with-token-whereas-able-to-connect/m-p/563285#M100366</link>
    <description>&lt;P&gt;happened to me as well,&amp;nbsp; did you find a solution?&lt;/P&gt;</description>
    <pubDate>Sat, 14 Aug 2021 15:54:10 GMT</pubDate>
    <dc:creator>chandika-cg</dc:creator>
    <dc:date>2021-08-14T15:54:10Z</dc:date>
    <item>
      <title>Getting 401 while connecting with token whereas able to connect with username and password</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Getting-401-while-connecting-with-token-whereas-able-to-connect/m-p/509053#M86583</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When i am using Splunk admin username and password, am able to get the indexes via below code&lt;/P&gt;&lt;PRE&gt;HttpService.&lt;SPAN&gt;setSslSecurityProtocol&lt;/SPAN&gt;(SSLSecurityProtocol.&lt;SPAN&gt;TLSv1_2&lt;/SPAN&gt;)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;ServiceArgs loginArgs = &lt;SPAN&gt;new &lt;/SPAN&gt;ServiceArgs()&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;loginArgs.setUsername(&lt;SPAN&gt;"USER"&lt;/SPAN&gt;)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;loginArgs.setPassword(&lt;SPAN&gt;"PASS"&lt;/SPAN&gt;)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;loginArgs.setHost(&lt;SPAN&gt;"HOST"&lt;/SPAN&gt;)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;loginArgs.setPort(&lt;SPAN&gt;8089&lt;/SPAN&gt;)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;loginArgs.setScheme(&lt;SPAN&gt;"https"&lt;/SPAN&gt;)&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;Service service = Service.&lt;SPAN&gt;connect&lt;/SPAN&gt;(loginArgs)&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;System.&lt;SPAN&gt;out&lt;/SPAN&gt;.println(&lt;SPAN&gt;"printing indexes" &lt;/SPAN&gt;+ service.getIndexes().values().toString())&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;But when I am trying to connect with the HEC token created via Splunk Web, I am getting 401 UnAuthorized exception&lt;/P&gt;&lt;PRE&gt;HttpService.&lt;SPAN&gt;setSslSecurityProtocol&lt;/SPAN&gt;(SSLSecurityProtocol.&lt;SPAN&gt;TLSv1_2&lt;/SPAN&gt;)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;Service service = &lt;SPAN&gt;new &lt;/SPAN&gt;Service(&lt;SPAN&gt;"HOST"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;8089&lt;/SPAN&gt;)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;service.setToken(&lt;SPAN&gt;"xxxxx-xxxx-xxxx-xxxx-xxxxxxxxx"&lt;/SPAN&gt;)&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;System.&lt;SPAN&gt;out&lt;/SPAN&gt;.println(&lt;SPAN&gt;"printing indexes" &lt;/SPAN&gt;+ service.getIndexes().values().toString())&lt;SPAN&gt;;&lt;BR /&gt;&lt;BR /&gt;Am getting below exception&lt;BR /&gt;Exception in thread "main" com.splunk.HttpException: HTTP 401 -- Unauthorized&lt;BR /&gt;at com.splunk.HttpException.create(HttpException.java:84)&lt;BR /&gt;at com.splunk.HttpService.send(HttpService.java:500)&lt;BR /&gt;at com.splunk.Service.send(Service.java:1295)&lt;BR /&gt;at com.splunk.HttpService.get(HttpService.java:169)&lt;BR /&gt;at com.splunk.ResourceCollection.list(ResourceCollection.java:288)&lt;BR /&gt;at com.splunk.ResourceCollection.refresh(ResourceCollection.java:331)&lt;BR /&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;should I use&amp;nbsp;service.setToken("Basic" +&amp;nbsp;&lt;SPAN&gt;"xxxxx-xxxx-xxxx-xxxx-xxxxxxxxx"&lt;/SPAN&gt;)&lt;SPAN&gt;; or there should be other configuration required to use token?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jul 2020 05:55:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Getting-401-while-connecting-with-token-whereas-able-to-connect/m-p/509053#M86583</guid>
      <dc:creator>akshgpt25</dc:creator>
      <dc:date>2020-07-16T05:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: Connection Reset - while connecting with token</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Getting-401-while-connecting-with-token-whereas-able-to-connect/m-p/509101#M86588</link>
      <description>&lt;P&gt;Can anyone please help me out here.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jul 2020 16:56:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Getting-401-while-connecting-with-token-whereas-able-to-connect/m-p/509101#M86588</guid>
      <dc:creator>akshgpt25</dc:creator>
      <dc:date>2020-07-14T16:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Getting 401 while connecting with token whereas able to connect with username and password</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Getting-401-while-connecting-with-token-whereas-able-to-connect/m-p/563284#M100365</link>
      <description>&lt;P&gt;Same happen to me as well, Can anyone help?&lt;/P&gt;</description>
      <pubDate>Sat, 14 Aug 2021 15:53:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Getting-401-while-connecting-with-token-whereas-able-to-connect/m-p/563284#M100365</guid>
      <dc:creator>chandika-cg</dc:creator>
      <dc:date>2021-08-14T15:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: Connection Reset - while connecting with token</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Getting-401-while-connecting-with-token-whereas-able-to-connect/m-p/563285#M100366</link>
      <description>&lt;P&gt;happened to me as well,&amp;nbsp; did you find a solution?&lt;/P&gt;</description>
      <pubDate>Sat, 14 Aug 2021 15:54:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Getting-401-while-connecting-with-token-whereas-able-to-connect/m-p/563285#M100366</guid>
      <dc:creator>chandika-cg</dc:creator>
      <dc:date>2021-08-14T15:54:10Z</dc:date>
    </item>
    <item>
      <title>Re: Getting 401 while connecting with token whereas able to connect with username and password</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Getting-401-while-connecting-with-token-whereas-able-to-connect/m-p/563287#M100367</link>
      <description>&lt;P&gt;Found the solution&lt;/P&gt;&lt;P&gt;you have to put the token like this&lt;/P&gt;&lt;PRE&gt;service.setToken(&lt;SPAN&gt;"Bearer xxxxx-xxxx-xxxx-xxxx-xxxxxxxxx"&lt;/SPAN&gt;)&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 Aug 2021 16:31:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Getting-401-while-connecting-with-token-whereas-able-to-connect/m-p/563287#M100367</guid>
      <dc:creator>chandika-cg</dc:creator>
      <dc:date>2021-08-14T16:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: Getting 401 while connecting with token whereas able to connect with username and password</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Getting-401-while-connecting-with-token-whereas-able-to-connect/m-p/573010#M101371</link>
      <description>&lt;P&gt;Did you ever solve this problem. It looks like it is a very common problem which I have run into myself. None of the suggestions have worked for me.&lt;/P&gt;&lt;P&gt;My code:&lt;/P&gt;&lt;P&gt;com.splunk.HttpService.setSslSecurityProtocol(com.splunk.SSLSecurityProtocol.TLSv1_2);&lt;/P&gt;&lt;P&gt;ServiceArgs loginArgs = new ServiceArgs();&lt;BR /&gt;loginArgs.setToken("Splunk 2f8c48b2-aa3b-466f-9c08-xxxxxxxxxxxx");&lt;BR /&gt;loginArgs.setHost("splunk-hec.mydomain.com");&lt;BR /&gt;loginArgs.setPort(8088);&lt;BR /&gt;loginArgs.setScheme("https");&lt;BR /&gt;&lt;BR /&gt;Service splunkService = Service.connect(loginArgs);&lt;/P&gt;&lt;P&gt;System.out.println("printing indexes" + splunkService.getIndexes().values().toString());&lt;/P&gt;&lt;P&gt;Gives:&lt;BR /&gt;Exception in thread "main" com.splunk.HttpException: HTTP 404 -- {"text":"The requested URL was not found on this server.","code":404}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note this works fine from cURL such as:&lt;/P&gt;&lt;P&gt;curl -H "Authorization: Splunk 2f8c48b2-aa3b-466f-9c08-xxxxxxxxxxxx" \&lt;BR /&gt;-H "X-Splunk-Request-Channel: bc805b0d-0151-4c6c-96dc-xxxxxxxxxxxx" \&lt;BR /&gt;&lt;A href="https://splunk-hec.mydomain.com:8088/services/collector/event" target="_blank" rel="noopener"&gt;https://splunk-hec.mydomain.com:8088/services/collector/event&lt;/A&gt; \&lt;BR /&gt;-d '{"sourcetype": "_json", "event": { "fieldA" : "valueA", "fieldB" : "valueB" } }'&lt;/P&gt;&lt;P&gt;One potential difference is the request channel which I have to include with cURL due to acknowledgement being turned on. I'm not sure how to provide that here but really would expect a different error if that was the problem.&lt;/P&gt;&lt;P&gt;Also my code works fine using username and password to as local Splunk instance I have.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Oct 2021 18:03:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Getting-401-while-connecting-with-token-whereas-able-to-connect/m-p/573010#M101371</guid>
      <dc:creator>klloden</dc:creator>
      <dc:date>2021-10-29T18:03:39Z</dc:date>
    </item>
  </channel>
</rss>

