How to authenticate with an API key using HttpURLConnection
I'm having a hard time using the Java HttpURLConnection. Ive tried using HttpClient but that also failed.
All I want to do is this:
curl -H "Authorization: Bearer 1111111111" https://company.aha.io/api/v1/features/APP-1
1111111111
is the API key.
This is my code so far.
URL url = new URL("https://company.aha.io/api/v1/features/APP-1");
connection = (HttpsURLConnection) url.openConnection();
//add request header for authentication
connection.setRequestProperty("Authorization", "Bearer " + token);
connection.connect();
System.out.println(connection.getResponseCode());
I keep getting a 404 code.
Thank you for the help.
java apache http httpurlconnection
add a comment |
I'm having a hard time using the Java HttpURLConnection. Ive tried using HttpClient but that also failed.
All I want to do is this:
curl -H "Authorization: Bearer 1111111111" https://company.aha.io/api/v1/features/APP-1
1111111111
is the API key.
This is my code so far.
URL url = new URL("https://company.aha.io/api/v1/features/APP-1");
connection = (HttpsURLConnection) url.openConnection();
//add request header for authentication
connection.setRequestProperty("Authorization", "Bearer " + token);
connection.connect();
System.out.println(connection.getResponseCode());
I keep getting a 404 code.
Thank you for the help.
java apache http httpurlconnection
404 means the resource you're requesting does not exist. Doescurl
return the same error?
– Phil
Nov 13 '18 at 0:27
When I type the cURL command I get an{"error":"Record not found."}
– Tags
Nov 13 '18 at 1:40
Try adding-v
to thecurl
command so you can see the headers. It most probably has a 404 status which means the URL is probably incorrect
– Phil
Nov 13 '18 at 2:12
When I use the flag-v
I get a connection. Im also showing this codeHTTP/2 401
This is the API I'm usinghttps://www.aha.io/api
– Tags
Nov 13 '18 at 2:27
add a comment |
I'm having a hard time using the Java HttpURLConnection. Ive tried using HttpClient but that also failed.
All I want to do is this:
curl -H "Authorization: Bearer 1111111111" https://company.aha.io/api/v1/features/APP-1
1111111111
is the API key.
This is my code so far.
URL url = new URL("https://company.aha.io/api/v1/features/APP-1");
connection = (HttpsURLConnection) url.openConnection();
//add request header for authentication
connection.setRequestProperty("Authorization", "Bearer " + token);
connection.connect();
System.out.println(connection.getResponseCode());
I keep getting a 404 code.
Thank you for the help.
java apache http httpurlconnection
I'm having a hard time using the Java HttpURLConnection. Ive tried using HttpClient but that also failed.
All I want to do is this:
curl -H "Authorization: Bearer 1111111111" https://company.aha.io/api/v1/features/APP-1
1111111111
is the API key.
This is my code so far.
URL url = new URL("https://company.aha.io/api/v1/features/APP-1");
connection = (HttpsURLConnection) url.openConnection();
//add request header for authentication
connection.setRequestProperty("Authorization", "Bearer " + token);
connection.connect();
System.out.println(connection.getResponseCode());
I keep getting a 404 code.
Thank you for the help.
java apache http httpurlconnection
java apache http httpurlconnection
asked Nov 13 '18 at 0:17
TagsTags
87212
87212
404 means the resource you're requesting does not exist. Doescurl
return the same error?
– Phil
Nov 13 '18 at 0:27
When I type the cURL command I get an{"error":"Record not found."}
– Tags
Nov 13 '18 at 1:40
Try adding-v
to thecurl
command so you can see the headers. It most probably has a 404 status which means the URL is probably incorrect
– Phil
Nov 13 '18 at 2:12
When I use the flag-v
I get a connection. Im also showing this codeHTTP/2 401
This is the API I'm usinghttps://www.aha.io/api
– Tags
Nov 13 '18 at 2:27
add a comment |
404 means the resource you're requesting does not exist. Doescurl
return the same error?
– Phil
Nov 13 '18 at 0:27
When I type the cURL command I get an{"error":"Record not found."}
– Tags
Nov 13 '18 at 1:40
Try adding-v
to thecurl
command so you can see the headers. It most probably has a 404 status which means the URL is probably incorrect
– Phil
Nov 13 '18 at 2:12
When I use the flag-v
I get a connection. Im also showing this codeHTTP/2 401
This is the API I'm usinghttps://www.aha.io/api
– Tags
Nov 13 '18 at 2:27
404 means the resource you're requesting does not exist. Does
curl
return the same error?– Phil
Nov 13 '18 at 0:27
404 means the resource you're requesting does not exist. Does
curl
return the same error?– Phil
Nov 13 '18 at 0:27
When I type the cURL command I get an
{"error":"Record not found."}
– Tags
Nov 13 '18 at 1:40
When I type the cURL command I get an
{"error":"Record not found."}
– Tags
Nov 13 '18 at 1:40
Try adding
-v
to the curl
command so you can see the headers. It most probably has a 404 status which means the URL is probably incorrect– Phil
Nov 13 '18 at 2:12
Try adding
-v
to the curl
command so you can see the headers. It most probably has a 404 status which means the URL is probably incorrect– Phil
Nov 13 '18 at 2:12
When I use the flag
-v
I get a connection. Im also showing this code HTTP/2 401
This is the API I'm using https://www.aha.io/api
– Tags
Nov 13 '18 at 2:27
When I use the flag
-v
I get a connection. Im also showing this code HTTP/2 401
This is the API I'm using https://www.aha.io/api
– Tags
Nov 13 '18 at 2:27
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271988%2fhow-to-authenticate-with-an-api-key-using-httpurlconnection%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271988%2fhow-to-authenticate-with-an-api-key-using-httpurlconnection%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
404 means the resource you're requesting does not exist. Does
curl
return the same error?– Phil
Nov 13 '18 at 0:27
When I type the cURL command I get an
{"error":"Record not found."}
– Tags
Nov 13 '18 at 1:40
Try adding
-v
to thecurl
command so you can see the headers. It most probably has a 404 status which means the URL is probably incorrect– Phil
Nov 13 '18 at 2:12
When I use the flag
-v
I get a connection. Im also showing this codeHTTP/2 401
This is the API I'm usinghttps://www.aha.io/api
– Tags
Nov 13 '18 at 2:27