Need use curl, inside go terminal

good day.

help is needed.

Can I either use the curl command in my projects?

do not use request,

For example curl (parameters string)?

var curlstr = `curl -H 'Host: www.bos.de' -H 'Cache-Control: max-age=0' -H 'Origin:     https://www.bos.de' -H 'Upgrade-Insecure-Requests: 1' -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryMB2FxJ70TX1UemBu' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3' -H 'Referer: https://www.bos.de/en/contact/send-message.html' -H 'Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7' -H 'Cookie: _ga=GA1.2.659292183.1561542752; _gid=GA1.2.611660608.1561542752' -H 'DNT: 1' --data-binary '------WebKitFormBoundaryMB2FxJ70TX1UemBu
Content-Disposition: form-data; name="tx_powermail_pi1[__referrer][@extension]"

Powermail
------WebKitFormBoundaryMB2FxJ70TX1UemBu
Content-Disposition: form-data; name="tx_powermail_pi1[__referrer][@vendor]"

In2code
------WebKitFormBoundaryMB2FxJ70TX1UemBu
Content-Disposition: form-data; name="tx_powermail_pi1[__referrer][@controller]"

Form
------WebKitFormBoundaryMB2FxJ70TX1UemBu
Content-Disposition: form-data; name="tx_powermail_pi1[__referrer][@action]"

form
------WebKitFormBoundaryMB2FxJ70TX1UemBu
Content-Disposition: form-data; name="tx_powermail_pi1[__referrer][arguments]"

YTowOnt98ee02f22bba789d397ac6678624087794688bcf3
------WebKitFormBoundaryMB2FxJ70TX1UemBu
Content-Disposition: form-data; name="tx_powermail_pi1[__referrer][@request]"

a:4:{s:10:"@extension";s:9:"Powermail";s:11:"@controller";s:4:"Form";s:7:"@action";s:4:"form";s:7:"@vendor";s:7:"In2code";}405f1bef0ad6e766c981df2a295a365e54c5fc44
------WebKitFormBoundaryMB2FxJ70TX1UemBu
Content-Disposition: form-data; name="tx_powermail_pi1[__trustedProperties]"

a:2:{s:4:"mail";a:1:{s:4:"form";i:1;}s:5:"field";a:7:{s:4:"__hp";i:1;s:9:"firstname";i:1;s:8:"lastname";i:1;s:5:"email";i:1;s:10:"callnumber";i:1;s:7:"company";i:1;s:7:"message";i:1;}}f5f40bc8468d58edae0aee164cda03327f5c5cd3
------WebKitFormBoundaryMB2FxJ70TX1UemBu
Content-Disposition: form-data; name="tx_powermail_pi1[mail][form]"

3
------WebKitFormBoundaryMB2FxJ70TX1UemBu
Content-Disposition: form-data; name="tx_powermail_pi1[field][__hp]"

------WebKitFormBoundaryMB2FxJ70TX1UemBu
Content-Disposition: form-data; name="tx_powermail_pi1[field][firstname]"

Deion www.google.com
------WebKitFormBoundaryMB2FxJ70TX1UemBu
Content-Disposition: form-data; name="tx_powermail_pi1[field][lastname]"

Sipes
------WebKitFormBoundaryMB2FxJ70TX1UemBu
Content-Disposition: form-data; name="tx_powermail_pi1[field][email]"

------WebKitFormBoundaryMB2FxJ70TX1UemBu
Content-Disposition: form-data; name="tx_powermail_pi1[field][callnumber]"

037-081-3533
------WebKitFormBoundaryMB2FxJ70TX1UemBu
Content-Disposition: form-data; name="tx_powermail_pi1[field][company]"

Monahan, Wisozk and Wilderman
------WebKitFormBoundaryMB2FxJ70TX1UemBu
Content-Disposition: form-data; name="tx_powermail_pi1[field][message]"

example text
------WebKitFormBoundaryMB2FxJ70TX1UemBu--
' --compressed 'https://www.bos.de/en/contact/send-message.html?tx_powermail_pi1%5Baction%5D=create&tx_powermail_pi1%5Bcontroller%5D=Form&cHash=c2f7e72652576d4f6dba8460063ff64e'`

curl(curlstr) ???

1 Like

You can use functions from os/exec to simply call curl with whatever arguments you like.

3 Likes

thanks

1 Like

I try send curl but not working(( in my case too big params

1 Like

I have never had an issue. What have you done? And what is the exact error you get back?

1 Like

if I do everything from the command line Mac OS, everything works out, the request goes away,
if it doesn’t work by means of go, no errors come, everything works, and I don’t understand how to track whether it works or not , but in this case not work((

1 Like

@ext you said it gave you an error in your first post. Now you say you don’t know wether or not you have an error but only know it doesn’t work.

So please show us code.

1 Like

look at how many parameters there are … it is possible to collect the request infinitely))

1 Like

https://play.golang.org/p/5B9Pw0FwuJI

1 Like

Please read the instructions and examples of the linked documentation.

  1. You need to pass in a single name of an exectuable as a string.
  2. You need to pass in each argument to the command as a single string to the variadic function
  3. You need to actually Run() the Cmd.
fmt.Println(exec.Command("curl", "https://example.com").Run())
1 Like

10, 20, 100… Should be doable with request as well… But “infinite” is not possible with curl for sure, but maybe with request (even though I have not yet tried)…

1 Like

pls ,I know this documentation, try my example before giving advice;)

1 Like

Nice to know, that you know about the documentation, but you probably didn’t read it, while I tried to run your code (even though I didn’t need to)

It tries to run a curl command like this:

curl "curl url -H 'Host: www.bos.de' -H 'Cache-Control: max-age=0' …"

So you call it with a single argument.

As I said earlier, you need to provide one argument per bash argument.

exec.Command("curl", "http://example.com", "-H", "Host: www.bos.de", "-h", "Cache-Control: max-age=0", …)
1 Like

yes that’s right, but what if there are a lot of parameters, even the converter from curls to post requests (there is one) does not help to make large requests, as in my example, to do this? even if the post request …

What am I doing?
I study the request through Charles, I copy the curl, and the task is to repeat the request in go.

In the example that I threw off a lot of parameters) so how can I be, how to parse them correctly, or automate the parsing of these parameters and make the request correctly?

Why I chose a curl, so because at the exit from the charles I get a ready-made curl request, it remains only to repeat

The task is just how to repeat, I have a ready-made request, and how can I repeat it? =)

1 Like

I have no clue who Charles is. But the one and only way to do this with curl via go is to split up your huge string into single strings, each string representing a single argument as understood and parsed by bash and then provide these strings one after the other as an argument to exec.Command.

As long as you try a single large string, curl won’t be able to understand that.

1 Like

I understood, in other words, it’s not very convenient in this case.

1 Like

No one said it were…

Of course you could write a tokenizer that takes your string and tokenizes it as bash would and then pass that slice of tokens to exec.Command, eg:

args = tokenize(originalInputString)
exec.Command("curl", url, args...)
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.