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:' -H 'Cache-Control: max-age=0' -H 'Origin:' -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:' -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]"

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

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

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

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

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

Content-Disposition: form-data; name="tx_powermail_pi1[__trustedProperties]"

Content-Disposition: form-data; name="tx_powermail_pi1[mail][form]"

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

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

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

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

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

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

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

example text
' --compressed ''`

curl(curlstr) ???

1 Like

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



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

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", "").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:' -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", "", "-H", "Host:", "-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.