appending multiple querystring variables with curl - django

I keep getting a 401 response when I try to use authentication = ApiKeyAuthentication() in my ModelResource.
I looked at Django Tastypie: How to Authenticate with API Key and he uses the get parameters to solve his issue. If I try use get parameters it picks up username but not api_key!
This works in browser
http://127.0.0.1:8000/api/v1/spot/8/?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50
Sending via curl in terminal doesn't pickup api_key parameter
curl --dump-header - http://127.0.0.1:8000/api/v1/spot/8/?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50
Why when using curl and appending 2 querystring parameters like ?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50 does it only pickup the first one. Is this not the correct way?

Typing & in the command line means run the preceding command in the background (thanks #Maccesch), because of this anything after the & is being treated as a new command.
Try wrapping the url in quotes.
curl --dump-header - "http://127.0.0.1:8000/api/v1/spot/8/?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50"

Related

"error": "invalid_client" while using Django OAuth toolkit

I was following the steps mentioned in the documentation for django rest framework.
I'm not able to proceed from step 4.
As mentioned in the documentation,
curl -X POST -d "grant_type=password&username=<user_name>&password=<password>" -u"<client_id>:<client_secret>" http://localhost:8000/o/token/
I have changed the above variables with my values.
curl -X POST -d "grant_type=password&username=admin&password=admin123" -u "5hKeHNtF3EKy3uCpJqaAe3mU2bGZTgJhsKKxIuAQ:pbkdf2_sha256$390000$VFcCOjIZkBFObellddDgKA$DXovC1UiuxRQ0KN/lARIdQmXcj8dnoJofkznmkkqsZY=" http://localhost:8000/o/token/
I tried to import the curl on postman and Im getting this error
Then I tried running the curl on Insomnia testing tool, and I got the request configured as in the screenshot.
Then I click send and I got an error
SO i changed 'Content-Type' to 'Form URL Encoded'
Now I'm geting an error
{
"error": "invalid_client"
}
I tried running the curl in shell also, and I'm getting an invalid syntax error
I'm stuck with this and don't know how to proceed with this. Please lend me a hand.
Thanks in advance...
I was using the hashed value for client_secret instead of the actual value.
How to get actual client_secret actual value?
Answer:
While creating new application, copy the Client secret before saving
the values
https://github.com/jazzband/django-oauth-toolkit/issues/1193

Tandem - Is there an equivalent to cURL in HP NonStop?

I need to execute a simple HTTP POST to a URL from the NonStop computer to make sure a service functions correctly. Is there a way to do this?
Use the built-in TACL commands to make an HTTP POST request. The TACL command POST allows you to send an HTTP POST request to a specified URL. For example:
POST url headers=content-type:text/plain
data=This is the request body

CSRF Token error when attempting to post from CURL to an API endpoint I control. How do I write the request?

I have not utilized this part of Django before, but I have an endpoint which is giving me a 403 error and is telling me that my request needs a csrf token. I was trying to figure out how best to get this since I was attempting to set up a bunch of curl requests to handle some simple queries to the endpoint. Likewise, I was thinking to also use POSTman, but I was not sure where documentation is to handle these request.
I have seen the cookie csrftoken, but when I was attempting to curl with it, it was still giving me a 403. thought it would looking something like this:
curl -d #profilepicturev2.png -b "csrftoken=Ebfn2OlfhSwFjAEQdoQon7wUjbynFoJqrtHMNPla3cy7ZfCMT9cxZ3OQHsbaedam" http://127.0.0.1:8000/api/files/uploader
Maybe I am mistaken? I am trying to send a photo to the server, so i was thinking that this would be correct and wasnt sure if i needed to add additional params in order to append additional data information.
i need to see your code, but i think you need to install "pillow" to send pictures in django !

POST request to Django DRF call working in cURL but not with Postman

I'm following the instructions to support TokenAuthentication in my rest-api site, shown here. Using cURL, I have been able to obtain my user's token (username - example, password - example), through the following command:
curl -X POST -d "username=example&password=example" localhost:8000/api/login/
This returns a successful response, with example's authentication token.
Yet when I do (what I think is) the same thing through Postman, it simply does not work. See image below.
From the error code (400 - Bad request), it seems like it's not even receiving the POST parameters at all. Can anyone help me here?
See your URL in postman. There is attached query String with the URL.So remove that query String from the URL and send parameters as a post request like this.
http://localhost:8000/api/login/
Even this is very old question, but if this answer would be helpful...
I had exactly same issue
solution:
don't put username and password in address bar,but only
and in body put json data of your username and password as below
be careful, don't use single quotation marks'', but use double quotation marks "" instead, otherwise will fail, no clue why
Depending on how your API is set up, you probably need to specify the content type in your request headers, Content-Type: application/json.

Send cookies with curl

I am using curl to retrieve cookies like so:
curl -c cookies.txt url
then I parse the cookie I want from the cookies.txt file and send the request again with the cookie
curl -b "name=value" url
Is this the correct way to send the cookie?
Is there a simpler way?
You can use -b to specify a cookie file to read the cookies from as well.
In many situations using -c and -b to the same file is what you want:
curl -b cookies.txt -c cookies.txt http://example.com
Further
Using only -c will make curl start with no cookies but still parse and understand cookies and if redirects or multiple URLs are used, it will then use the received cookies within the single invoke before it writes them all to the output file in the end.
The -b option feeds a set of initial cookies into curl so that it knows about them at start, and it activates curl's cookie parser so that it'll parse and use incoming cookies as well.
See Also
The cookies chapter in the Everything curl book.
.example.com TRUE / FALSE 1560211200 MY_VARIABLE MY_VALUE
The cookies file format apparently consists of a line per cookie and each line consists of the following seven tab-delimited fields:
domain - The domain that created AND that can read the variable.
flag - A TRUE/FALSE value indicating if all machines within a given domain can access the variable. This value is set automatically by the browser, depending on the value you set for domain.
path - The path within the domain that the variable is valid for.
secure - A TRUE/FALSE value indicating if a secure connection with the domain is needed to access the variable.
expiration - The UNIX time that the variable will expire on. UNIX time is defined as the number of seconds since Jan 1, 1970 00:00:00 GMT.
name - The name of the variable.
value - The value of the variable.
From http://www.cookiecentral.com/faq/#3.5
if you have Firebug installed on Firefox, just open the url. In the network panel, right-click and select Copy as cURL. You can see all curl parameters for this web call.
Very annoying, no cookie file exmpale on the official website https://ec.haxx.se/http/http-cookies.
Finnaly, I find it does not work, if your file content is just copyied like this
foo1=bar;foo2=bar2
I gusess the format must looks the style said by #Agustí Sánchez
. You can test it by -c to create a cookie file on a website.
So try this way, it works
curl -H "Cookie:`cat ./my.cookie`" http://xxxx.com
You can just copy the cookie from chrome console network tab.