Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8230615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:11:35+00:00 2026-06-07T17:11:35+00:00

I Am writing a test porgram in java to test my connections to a

  • 0

I Am writing a test porgram in java to test my connections to a restfull api in django (djangorestframework to be precisely).
One of the options is to test on of the api’s with curl.
Running the curl command from the shell it works fine:
e.g.:

curl --show-error --request GET --header 'Accept: application/json' --user "user:pwd" http://127.0.0.1:8000/api/v1/

this returns nicely the api root urls and helptext in json format.

Now when I try to invoke the same from java, using ProcessBuilder, i get this answer:

{"detail": "You do not have permission to access this resource. You may need to login or otherwise authenticate the request."}

the java code I Am using is:

ProcessBuilder p=new ProcessBuilder("curl","--show-error", "--request","GET",
                    "--header","'Accept: application/json'", "--user","\"" + userName + ":" + password + "\"", getApiRootUrlString());
final Process shell = p.start();

Because I also catch the error stream by:

InputStream errorStream= shell.getErrorStream();
InputStream shellIn = shell.getInputStream();

I Know he starts the curl command, because making a mistake in one of the options shows the curl help text.

I Am not quit sure what’s the difference between invoking it, pretty sure it’s the same command.

by the way, ‘getApiRootUrlString()’ returns the correct url: http://127.0.0.1:8000/api/v1/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:11:38+00:00Added an answer on June 7, 2026 at 5:11 pm

    Each string you pass to the ProcessBuilder constructor represents one argument, so you don’t need the quotes that you would have to use with the shell. Try the following:

    ProcessBuilder p=new ProcessBuilder("curl","--show-error", "--request","GET",
                    "--header","Accept: application/json", "--user", userName + ":" + password, getApiRootUrlString());
    

    If you use quotes then they become part of the value that’s passed to the process, so you were trying to authenticate with a username of "user and a password of pwd".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I writing test cases for Android apps using Robotium. One of my test cases
I am writing a test program to understand vector 's better. In one of
Basically, I'm writing a Java Command-line application which accept parameter from user by readLine.
I am writing a java program, and I have a test to see what
I am writing an automated test program using curl-loader, to send calculated requests to
I am writing a Java program that inputs a test file, performs some modifications
I'm writing a simple test program to pass multidimensional arrays. I've been struggling to
So I'm writing a program to test the endianess of a machine and print
I'm writing a program similar to a diagnostic program , that runs a test
In writing Test case as I know, first step/task is to identify the Test

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.