How to urlencode curl messages?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to urlencode curl messages?
# 1  
Old 07-21-2019
How to urlencode curl messages?

i have script got error when curl message . i think have some problem with character "space" or other because when i tried skip space , script running normal.


this is my script :


Code:
#!/bin/env bash 
hostname="$(hostname)" now="$(date +'%d%h%y_%H.%M.%S')"  while IFS= read -r line;  do curl -X GET "http://x.x.x.x:5000/submit_fajar.php?msg=\"${line}+$line+$hostname\"" done < <(cat test.txt | strings | awk -F'|' '$4 > 100{print $1 "_" $2 "_" "please check have_many_error respond_from server" "_" $3 "_" "count", $4}')

when running got error :


Code:
+ curl -X GET 'http://x.x.x.x:5000/submit_fajar.php?msg="2019-07-20_19:42_please check have_many_error respond_from server_server busy_count 176+2019-07-20_19:42_please check have_many_error respond_from server_server busy_count 176+server"' 
<html><body><h1>400 Bad request</h1> Your browser sent an invalid request. </body></html> + IFS= + read -r line

please help how to url encode my messages to curl. Thanks.
# 2  
Old 07-22-2019
Here is an easy PHP way, as a high level example:

Code:
<?php
$encoded  = urlencode($string_to_encode);
$results = file_get_contents($encoded);

Cheers.
# 3  
Old 07-22-2019
If you want this in bash, you could define a function to call:
Code:
function encode_url () {
   printf "%s" "$*" | perl -pe 's/([^0-9a-zA-Z_])/sprintf("%%%02x",ord($1))/ge'
}

The in your code you can write:
Code:
my_encoded_message="$(encode_url "${my_message}")"


Does that give you what you need? For my_message="Hello world" it puts the string Hello%20world in my_encoded_message



Kind regards,
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Curl command

Hi All, I am using below curl commad and getting output data correctly curl -k -u AASSDD:PPOOII -d "output_mode=csv" --data-urlencode search='search source=*/AASSDDFF/PPOOLLKK**/94.0*ASD-RST* "Caused by" OR "Error: LISTENER WILL BE DISABLED" OR java.lang.reflect.InvocationTargetException |... (1 Reply)
Discussion started by: rakeshtomar82
1 Replies

2. Shell Programming and Scripting

Curl -v logs

Hi All, Seeking for your assistance on how to redirect into another files the logs of curl -v i tried this code below but i got 0 logs. curl -v 'http://127.0.0.0.......' >> test.logs Thanks in advance. BR, (2 Replies)
Discussion started by: znesotomayor
2 Replies

3. Shell Programming and Scripting

Help with curl command

HI I am trying to write a script where i can enter a dvd's bar code at the cli and return the price sites will pay for the dvd. the bard code im using for testing is this site is through use of httpfox i have found some info whic i need to use with curl ctl00$ScriptManager1... (4 Replies)
Discussion started by: dunryc
4 Replies

4. Solaris

Need help for Curl package

Hi all, I need the same curl package installed on system1 to be installed on other system2. Both machines are Solaris 10 System1: -bash-3.00$ pkginfo | grep curl system SFWcurl curl - tool for transfering data specified with URL syntax ... (4 Replies)
Discussion started by: manalisharmabe
4 Replies

5. Shell Programming and Scripting

Help with cURL

Hi all; first of all i need to clarify that i am new to apache2 server configuration and for some needs i want to transfer some files using curl to web directory,so please bear with me: following is the command i m running to transfer file to my web directory: curl -T "q"... (4 Replies)
Discussion started by: arien001
4 Replies

6. Programming

cURL and cgi

I have a CGI application done in c++ that communicates with PayPal. I've had an issue where the application dies when I try to perform a cURL operation. Upon further inspection it seems that I can run cURL examples from the command line. Upon even further inspection it seems that I can run... (8 Replies)
Discussion started by: tatebn
8 Replies

7. Shell Programming and Scripting

how to urlencode a string?

Hi there, I'm desperatly trying to encode a url in a shell script. localhost:~# cat sendalert.sh #!/bin/bash url="http://www.xxxxx.fr/addalert.php?login=xxx&pass=xxx&msg=" url+=$(php -r "echo rawurlencode('$1');") echo $url # wget -O- "$url" localhost:~# ./sendalert.sh "hello world"... (2 Replies)
Discussion started by: chebarbudo
2 Replies

8. Shell Programming and Scripting

use of curl

I have to transfer a file from my aix box to another server using ftps protocol, how can i achieve this using curl preferably or any other utility. Regards Sandeep (0 Replies)
Discussion started by: jayawantsandeep
0 Replies

9. AIX

use of curl

Hi guys , need some help I have to transfer a file from my aix box to another server using ftps protocol, how can i achieve this using curl preferably or any other utility. Thanks Sandeep (0 Replies)
Discussion started by: jayawantsandeep
0 Replies

10. Shell Programming and Scripting

curl

Aren't there any way to download files as below? For example, I want to download all .html files under the root directory of unix.com/ curl -O https://www.unix.com/*.html This won't work, but please tell me the way to do this. Well, the best way is to get the file list of the directory, but i... (6 Replies)
Discussion started by: Euler04
6 Replies
Login or Register to Ask a Question