I want to test my rails app using "wget", specifically the part that returns JSON-data. I don't really understand the syntax I should use. I have tried this:
wget --user=username#example.com --password=somepass localhost:3000/folders/1.json
and variations of it, without any success. Which is the exact syntax? Would it be better to use CURL instead?
-- edit --
I found at this blog:
http://blogs.operationaldynamics.com/andrew/software/research/testing-rest-the-hard-way
this suggestion:
$ wget -S -q --header "Accept: application/json" -O - http://localhost:3000/folders/1
but even when I add
--user=username#example.com --password=somepass
...I get 401 Unauthorised. The username is correct, I can login via the browser.
curl -u username:password http://localhost:3000/folders/1.json
Read more here http://curl.haxx.se/docs/manpage.html#-u
An alternative to curl is the less well known but equally capable httpie - https://github.com/jkbrzt/httpie - I find it to be a bit more straightforward and friendly to use, and includes syntax colouring for output.
http -a user:pass :3030/folders/1.json would do the trick here, I think.
Related
I integrated linkedin with Rails 4 and trying to share post on linkedin.
I used curl in rails and post on linked-in wall using below curl post. I used below code in rails console and its work fine but when i used it in rails code with system and single quote then issue create because already single quote use in inside.
system 'curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"comment":"hello from system www.google.com! http://google.com","visibility":{"code":"anyone"}}' https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=xxxxxXygzp_8E3xxvg7_7FaxxxxxxnxtWzBXAxxxxa0wta5z1MVK6-kubHJ5JxxxndpAMc_CxmCsIHxFlxxx0t_WNEhxxxMz8_cKpeOidAxxx5-X-MdvzYVxxQ&format=json&title=linkedin HTTP/1.1'
What do I have to add to resolve this issue? I tried a lot then I posted here.
Thanks in advance.
In your application (as opposed to in the terminal), I suggest you use an HTTP library (I use HTTParty, but there are many options).
I'm struggling about how I can send an unknow number of files to my rails app using curl.
This is my curl request to POST with one file :
curl -H 'Authorization: Token token=your_token' -X POST -F job[webapp_id]=2 -F job[file]=#test.txt localhost:3000/api/v0/jobs
It works.
I would like to allow the user to send as much as file as he wants with something like :
-F job[files][]=#test1.txt -F job[files][]=#test2.txt
-F job[files[]]=#test1.txt -F job[files[]]=#test2.txt
But it's not working.
I also tried with :
-F job[files[0]]=#test.txt -F job[files[1]]=#test2.txt
Still not working. I think it's because I don't know how to tweak my permit parameters. I get an empty array.
Any idea on how to do it with one request ?
RestClient may be easier to work with.
I have tried:
curl -v --http1.0 --data "mac=00:00:00" -F "userfile=#/tmp/02-02-02-02-02-22" http://url_address/getfile.php
but it fails with the following message:
Warning: You can only select one HTTP request!
How can I send a mix of data and file by curl? Is it possible or not?
Thank you
Read up on how -F actually works! You can add any number of data parts and file parts in a multipart formpost that -F makes. -d however makes a "standard" clean post and you cannot mix -d with -F.
You need to first figure out which kind of post you want, then you pick either -d or -F depending on your answer.
I need a transformation of the following working curl command:
curl --data-binary #"data.txt" http://www.example.com/request.asp
The data.txt includes this:
foo=bar
parameter1=4711
parameter2=4712
The key is I need to send the linebreaks and they are \r\n. Its working with the file because it has the right encoding but how do I manage to get this curl command run without the file? So a 1-liner sending the parameters with the correct \r\n on end of each.
All my tests with different URL encoding, etc. didn't work. I never got the same result like with the file.
I need this information because I have serious trouble to get this post run on my Ruby on Rails App using net/http.
Thanks!
One way to solve it is to generate the binary stream with something on the fly, like the printf command, and have curl read the data from stdin:
printf 'foo=bar\r\nparameter1=4711\r\nparameter2=4712' | curl --data-binary #- http://example.com
I'm trying to make use of the CO-OP API for some purposes in my app (http://coopapp.com/api)
I know how to preform the request using curl:
curl http://coopapp.com/groups/20/statuses -H 'Accept: application/xml' \ -H 'Content-Type: application/xml' -u email:password
But I can't figure out how to do this in iOS, hopefully somebody can give me a push in the right direction.
You do that with the NSURLConnection class. But I recommend using MKNetworkKit which is a handy wrapper around it. It actually even shows the equivalent curl command in the description of its operations.
If you want to load the same web page use UIWebView,Same HTML page will be loaded