I am trying to do a basic auth to Jira, but i keep receiving the error 403 forbidden.
My code is :
package br.com.indra.jiraauto.authentication;
import static java.lang.System.out;
import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;
public class authentication
{
public static void main(String[] args) {
//code
CredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("username", "password");
provider.setCredentials(AuthScope.ANY, credentials);
HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
HttpResponse response;
try {
response = client.execute(new HttpGet("https://localhost:8080/rest/api/2/issue/project-1"));
int statusCode = response.getStatusLine().getStatusCode();
out.println("Response Code :"+ statusCode);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
thanks , but I've made it work with this code:
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
public class getIssue {
public static void main(String[] args) {
try {
HttpResponse<String> response = Unirest.get("<jiralink>")
.header("Content-Type", "application/json")
.header("Authorization", "Basic <64login:pass>")
.header("cache-control", "no-cache")
.asString();
System.out.println(response.getCode());
System.out.println(response.getBody());
} catch (UnirestException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Hello Rafael,
There are a couple things to check to ensure your account is working as expected.
Please let us know if if these help or if you’re still getting a 403 response.
Regards,
Stephen Sifers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.