I am sending a curl request pointing to an url containing unsafe characters in it like /test/#/test1.html
I tried below possible ways but was not working. The Url ends when it sees a # in it and the remaining part is not processed. I took a packet capture and found that the url which is sent by curl is just http://<someIP>testsite/ and not http://<someIP>testsite/#/file.html
curl -v -X 'GET' "http://<someIP>/testsite/#/file.html" -D header.txt -o body.txt
curl -v -X 'GET' 'http://<someIP>/testsite/#/file.html' -D header.txt -o body.txt
Could somebody help in answering how to escape the # or how to make curl to send this complete URL ?
What's after # is never sent to the server in the HTTP request. That can only be read through some client side code (js for example). There is no way of making Curl send that.
I am not sure if this helps, but you can try to encode # char to a URL "safe version": %23
Here you can find more useful information: http://www.url-encode-decode.com/
Related
I'm having trouble sending large messages via bot telegrams. During the search for the problem, I threw off all the extra binding and tested it with curl.
In the case of sending a message with text up to about 1500, everything works, I sent it like this:
curl -s -X POST https://api.telegram.org/bot<ТОКЕН>/sendMessage -d chat_id = <ID_CHATA> -d text = "1100ertyikgnfdhgmcndgbtowewerttysadasdsasadsadddssasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsas "asadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsadsasasadsasasadsasasadsasasadsasasadsadsasasadsadsasasadsadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasasadsas"
In the case of sending a large message, it stops working, in this case I send a text of 2200 characters in size:
curl -s -X POST https://api.telegram.org/bot<ТОКЕН>/sendMessage -d chat_id = <ID_CHATA> -d text = "2200ertyikgnfdhgmcndgbtowewerttysadasdsasadsadddssasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsas asadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasertyikgnfdhgmcndgbtowewerttysadasdsasadsadddssasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasas adsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsadsasasadsadsasasadsadsasasadsasasadsasasadsasasadsasasadsasasadsasasasasasasasasasasasadsasasadsasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsas
Using the -vvvvvv switch for curl, I saw the following details: In the first case (when the message is small and sending is triggered) I see:
Expect: 100-continue HTTP / 1.1 100 Continue HTTP / 1.1 200 OK
In the second case (when I send a large message and the sending does not work) I see:
Expect: 100-continue HTTP / 1.1 100 Continue Empty reply from server Connection #0 to host api.telegram.org left intact Closing connection #0
There seems to be an error in the second CURL request. the -d param requires a string;
curl -s -X POST https://api.telegram.org/bot<ТОКЕН>/sendMessage -d "chat_id=<ID_CHATA>" -d "text='200ertyikgnfdhgmcndgbtowewe'"
Also you close the string before the last char, curl doesn't like that;
" sasasasasasasasasasasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsas
If I edit your second command to use -d "", I can send it as expected.
Even with a message of 2578 chars works just fine.
Google tels me there is an 4096 UTF8 char limit; Git
Telegram even send an TOO_LONG if the text param is too long ;) So
Edit based on comment;
Full command for bash;
curl -s -X POST https://api.telegram.org/bot123456:abcdefghijk/sendMessage -d "chat_id=123456" -d "text='Test'"
If this does not work for you, please show the error you receive after running the command
I'm looking to this snippet of code:
curl -X GET 'https://api.newrelic.com/v2/applications/1622/metrics/data.json' \
-H 'X-Api-Key:30f4ec24a1f7dd9998a536b05840b17f7d42c7c1' -i \
-d 'names[]=EndUser&names[]=EndUser/Apdex&values[]=call_count&values[]=average_response_time&values[]=score&summarize=true'
from "Listing your app ID and metric data".
But curl's man page only talks about -d/--data in the context of POST requests, so, what's really happening here in terms of the HTTP request sent to the server?
-d with GET request just sends a query string, however the endpoint where data are sent must be set to consume application/x-www-form-urlencoded content type - have just checked that.
In general it's weird and I wouldn't implement it in such a way.
When such query is sent to java servlet - the body is accessible via.. getInputStream() method [sic!].
In slack you can script slackbot to post messages to a channel like this:
curl --data "$msg" $'https://<yourteam>.slack.com/services/hooks/slackbot?token=<yourtoken>&channel=#random'
Now i'd like to mention a username as the first part of the message like msg="#joernhees hello self".
The problem with this is that if the --data argument of curl starts with an # sign it will interpret the string after the # as filename and post its content. Is there a way to make curl ignore the # sign and to send a literal # as the first char of a post request?
If you are on a new version of cURL you can also use the --data-raw option:
http://curl.haxx.se/docs/manpage.html#--data-raw
A word of warning is that looking my laptop it appears Yosemite ships with an older version of cURL.
In general if you're creating tools to post to Slack I'd recommend using an HTTP library in your script rather than calling out to a shell and invoking the curl command.
Actually i just found out i can do this (not sure it's the best option though):
curl --data '#-' $'https://<yourteam>.slack.com/services/hooks/slackbot?token=<yourtoken>&channel=#random' <<< "$msg"
The trick is to tell curl to read from stdin #- and then pass the message in via that.
The request for our service looks something like this:
GET http://[SERVICE]/Node:[id].Build?format=mime1,mime2,...,mimeN&template-id=[templateid]
Accept: multipart/mixed
Content-Type: application/json
body: json document
I am attempting to use ApacheBench to test benchmark this. Here is the call I am using:
ab -n 10 -c 2 -T 'application/json' -H 'Accept: multipart/mixed' 'http://phx5qa01c-02b0.stratus.phx.qa.ebay.com/.Build?format=text/html,text/plain&template-id=29b1468f-c8c3-db23-2f6f-74e112795540'
This call goes through, and results in an error since the expected json data is not there.Is there a way in ab to supply the necessary json along with this request. I see there are -p and -u commands to specify an input file, but those are for puts and posts.
I realize that this answer is six years late, but I think it is worth posting since I was banging my head against a wall on a very similar issue to this, in which I was trying to load test a URL which returned only JSON data, and my solution might help other readers encountering this issue. My issue was I kept specifying the -H option when I didn't need to. That kept making the server to send back an HTTP 406 response code (Not Acceptable) to my AB request. During most of my my troubleshooting, I had also kept -T 'application/json' in the AB request as well when I didn't need it. That is only used in conjunction with PUTs or POSTs (when using the -p switch). So I removed -H, and -T, and it worked. All that said, I see those two issues here. We need to be mindful that AB uses the GET method by default.
You are constraining AB by appending extra custom headers to the
request, by using the -H option: -H 'Accept: multipart/mixed', which
might make your target server think it's an invalid request and stop the
sequence right then and there. Just don't use -H unless you have a
really good reason why.
You are using the -T option: -T 'application/json' which
only works when you specify that in conjunction with -p and you
don't have -p anywhere in your command, which you don't want to use anyway since you are sending a GET and not a PUT or a POST.
So to fix this, simply remove both the -T and -H options, and it should work. Reminder to other readers: If on Windows, enclose the URL in double-quotes whenever it contains special characters like a "&", or a "?", as in this case.
ab -n 10 -c 2 'http://phx5qa01c-02b0.stratus.phx.qa.ebay.com/.Build?format=text/html,text/plain&template-id=29b1468f-c8c3-db23-2f6f-74e112795540'
i need to call a HTTP request in ubuntu how do i do it? I can't seem to find an answer around on how to to do it?
How do run the following url without calling a browser like lynx to do it?
http://www.smsggglobal.com/http-api.php?action=sendsms&user=asda&password=123123&&from=123123&to=1232&text=adsdad
in your command prompt, run the following:
curl http://www.smsggglobal.com/http-api.php?action=sendsms&user=asda&password=123123&&from=123123&to=1232&text=adsdad
the curl command executes an http request for a given url and parameters.
if you need to specify another HTTP method, use curl -X <TYPE> <URL>, like this:
curl -X POST http://www.smsggglobal.com/http-api.php?action=sendsms&user=asda&password=123123&&from=123123&to=1232&text=adsdad
curl documentation: http://curl.haxx.se/docs/manpage.html
to display the results:
curl http://www.smsggglobal.com/http-api.php?action=sendsms&user=asda&password=123123&&from=123123&to=1232&text=adsdad
or
to save the results as a file
wget http://www.smsggglobal.com/http-api.php?action=sendsms&user=asda&password=123123&&from=123123&to=1232&text=adsdad