title: Basic Authentication for JAVA Application using OkHttp
body: <p>First I wanted to authenticate my java application using OkHttp and then after authentication the response returns a session ID(key) that I wanted to use in subsequent API calls. below is the code that I am using to achieve this.</p>
  <pre><code>    String url = &quot;my application url&quot;;
      String username = &quot;xxx&quot;;  
      String password = &quot;zzz&quot;;  
      String userpass = username + &quot;:&quot; + password;  
      String basicAuth = &quot;Basic :&quot; + new String(Base64.getEncoder().encode(userpass.getBytes()));  
     
      OkHttpClient client = new OkHttpClient();
      Response response ;
      Request request = new Request.Builder()
                       .url(url)
                       .addHeader(&quot;Authorization&quot;, basicAuth)
                       .build();
      response = client.newCall(request).execute();
      
      if (!response.isSuccessful()) throw new IOException(&quot;Unexpected code &quot; + response);
  
       System.out.println(response.body().string());
  </code></pre>
  <p>but its throwing an error saying
  {&quot;responseStatus&quot;:&quot;FAILURE&quot;,&quot;responseMessage&quot;:&quot;Request method 'GET' not supported&quot;,&quot;errorCodes&quot;:null,&quot;errors&quot;:[{&quot;type&quot;:&quot;METHOD_NOT_SUPPORTED&quot;,&quot;message&quot;:&quot;Request method 'GET' not supported&quot;}],&quot;errorType&quot;:&quot;GENERAL&quot;}</p>
  <p>can someone please help me to solve this. or if any have any other idea to authenticate a java application using okhttp then please suggest...</p>