Curl post multipart file to spring boot rest endpoint - spring

I am trying to post a file to a restful endpoint implemented in spring boot using Curl and it throws the following error:
$ curl -v http://localhost:8081/qas/uploadCsv -X POST -F "file=#test.csv"
Note: Unnecessary use of -X or --request, POST is already inferred.
* timeout on name lookup is not supported
* Trying ::1...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to localhost (::1) port 8081 (#0)
> POST /qas/uploadCsv HTTP/1.1
> Host: localhost:8081
> User-Agent: curl/7.46.0
> Accept: */*
> Content-Length: 4257762
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------e16823418f4c8f54
>
< HTTP/1.1 100 Continue
} [155 bytes data]
< HTTP/1.1 400 Bad Request
< Server: Apache-Coyote/1.1
< X-Application-Context: application:8081
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Mon, 11 Apr 2016 14:27:42 GMT
< Connection: close
<
{ [247 bytes data]
100 4158k 0 236 100 4157k 1888 32.4M --:--:-- --:--:-- --:--:-- 32.4M{"timestamp":1460384862046,"status":400,"error":"Bad Request","exception":"org.springframework.web.bind.MissingServletRequestParameterException","message":"Required MultipartFile parameter 'file' is not present","path":"/qas/uploadCsv"}
* Closing connection 0
I must be missing something basic but cannot see what it is. It is looking for the request param 'file' and am not sure how to send this through Curl.
Spring java config has following beans:
#Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setMaxFileSize("1000MB");
factory.setMaxRequestSize("1000MB");
return factory.createMultipartConfig();
}
#Bean
public MultipartResolver multipartResolver() {
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
multipartResolver.setMaxUploadSizePerFile(10000000);
return multipartResolver;
}
My spring boot web service is as follows:
#RequestMapping(value = "/uploadCsv", method = RequestMethod.POST, consumes = {"multipart/*"})
public #ResponseBody result handleFileUpload(#RequestParam("file") MultipartFile file) {
in the above signature it is looking for the requestParam file which correlates with the cUrl error.
"status":400,"error":"Bad Request",
"exception":"org.springframework.web.bind.MissingServletRequestParameterException",
"message":"Required MultipartFile parameter 'file' is not present","path":"/qas/uploadCsv"}
This request works in postman which submits the following request:
POST /qas/uploadCsv HTTP/1.1
Host: localhost:8081
Cache-Control: no-cache
Postman-Token: d62a469b-16c8-b30a-4168-7622d9695c57
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename=""
Content-Type:
----WebKitFormBoundary7MA4YWxkTrZu0gW
I also have a mockMvc integration test that works fine. Comparing the two (cUrl vs postman) in the cUrl there is no content disposition which contains the file param. Have looked around on google and cannot see to send this request? Any pointers
Thanks in advance
UPDATE:
I tried the solution in the following link
File upload working under Jetty but not under Tomcat
Using the same cURL command above the file is null throwing the error below
$ curl -v http://localhost:8081/qas/uploadCsv -X POST -F "file=#test.csv" -H "Content-Type: multipart/form-data"
Note: Unnecessary use of -X or --request, POST is already inferred.
* timeout on name lookup is not supported
* Trying ::1...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to localhost (::1) port 8081 (#0)
> POST /qas/uploadCsv HTTP/1.1
> Host: localhost:8081
> User-Agent: curl/7.46.0
> Accept: */*
> Content-Length: 4257762
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------e6cd31736e52dfa2
>
< HTTP/1.1 100 Continue
} [155 bytes data]
100 4157k 0 0 100 4157k 0 681k 0:00:06 0:00:06 --:--:-- 0< HTTP/1.1 500 Internal Server Error
< Server: Apache-Coyote/1.1
< X-Application-Context: application:8081
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Tue, 12 Apr 2016 07:23:18 GMT
< Connection: close
<
100 4157k 0 0 100 4157k 0 622k 0:00:06 0:00:06 --:--:-- 0{ [4 bytes data]
100 4158k 0 174 100 4157k 26 622k 0:00:06 0:00:06 --:--:-- 0{"timestamp":1460445797961,"status":500,"error":"Internal Server Error","exception":"java.lang.NullPointerException","message":"No message available","path":"/qas/uploadCsv"}
* Closing connection 0

Curl POST + Multipart
To POST with a file, add this -F file=#"path/to/data.txt"
curl -F file=#"test.csv" http://localhost:8081/qas/uploadCsv

I think this is due to the fact that file here is not a parameter. According to Spring web, a parameter is a 'query' parameter, so for example /api?foo=bar, foo is here the parameter in this request.
So in your case, Spring complains about a missing parameter file because it expects the request to look like http://localhost:8081/qas/uploadCsv?file=something.
Changing the method signature from
handleFileUpload(#RequestParam("file") MultipartFile file)
to
handleFileUpload(#RequestPart("file") MultipartFile file)
should fix your issue

Related

AWS Fail to set timeout on ALB, Service, Task

I've got an unexpected error, I guess it's about timeout.
Task takes time quite long. generally less than 1minute. There is no problem when it fininsh before 1 minute. But sometimes task takes more than 1 minute. Error occurs when it takes more than 1minute. Please see below.
[ec2-user#ip-000-00-0-00 ~]$ curl --location --request POST 'userid.ap-northeast-2.elb.amazonaws.com:port/service' -d "video.mp4" -o output.json -v
Note: Unnecessary use of -X or --request, POST is already inferred.
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 172.31.74.35:5000...
* Connected to loadbalancer.ap-northeast-2.elb.amazonaws.com (000.00.00.00) port 0000 (#0)
> POST /service HTTP/1.1
> Host: userid.ap-northeast-2.elb.amazonaws.com:port
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Length: 37
> Content-Type: application/x-www-form-urlencoded
>
} [37 bytes data]
100 37 0 0 0 37 0 0 --:--:-- 0:00:59 --:--:-- 0* Mark bundle as not supporting multiuse
< HTTP/1.1 500 Internal Server Error
< Date: Tue, 19 Apr 2022 01:45:23 GMT
< Content-Type: application/octet-stream
< Content-Length: 0
< Connection: keep-alive
< Server: Python/3.7 aiohttp/3.7.4.post0
<
100 37 0 0 0 37 0 0 --:--:-- 0:01:00 --:--:-- 0
* Connection #0 to host loadbalancer.ap-northeast-2.elb.amazonaws.com left intactm left intact
With curl verbose option, I get 500 Internal Server Error at 0:00:59. How can I finish my task which takes more than 1minutes?
I've tried
increasing Health check grace period for ECS Service
increasing idle timeout of Load Balancer
increasing timeout and interval of Target group
curl options (like keep-alive, max-time)
My EC2 Instance
type : t2.micro
Amazon Linux
My Service
Service type : REPLICA
Launch type : FARGATE
My task in service
Network mode : awsvpc
Compatibilities : EC2, FARGATE
Requries compatibilities : FARGATE
EFS mounted
Docker
Appreciate,

Calling a tibco soap webservice using shell script

I am trying to calling a TIBCO soap based web service through shell script using curl. I am getting response as 200 ok but am not getting output in response.xml
Tibco webservice is deployed in three instances. I am trying to hit one of the instance and retrieve response but I am getting content-length as 0.
I tried using curl and wget to call webservice and retrieve response but am getting content-length as 0.
Below is the curl command:
curl -v --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction: "/ServiceImplV1.0/getInfo"/" --data #request2.xml http://sfapt-ap98t:4121/service/dataservice -o response.xml
request2.xml
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://www.greatclips.com/ghf/tck/service/v1.0">
<soapenv:Header/>
<soapenv:Body>
<v1:GetBaseLineRequest>
<!--Optional:-->
<UniqueRequestIdentifier>?</UniqueRequestIdentifier>
</v1:GetBaseLineRequest>
</soapenv:Body>
</soapenv:Envelope>
Response Hostname was NOT found in DNS cache
* Trying 10.215.13.217...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to dlfapt-ap98a (10.215.13.217) port 6121 (#0)
> POST /service/addataservice HTTP/1.1
> User-Agent: curl/7.37.0
> Host: dlfapt-ap98a:6121
> Accept: */*
> Content-Type: text/xml;charset=UTF-8
> SOAPAction: /ServiceImplV1.0/getBaseLineDetails/
> Content-Length: 323
>
} [data not shown]
Response from server:
* upload completely sent off: 323 out of 323 bytes
< HTTP/1.1 200 OK
< Content-Length: 0
< Date: Fri, 19 Jul 2019 17:57:45 GMT
* Server is not blacklisted
< Server:
<
100 323 0 0 100 323 0 19383 --:--:-- --:--:-- --:--:-- 35888
* Connection #0 to host dlfapt-ap98a left intact

curl post request is not working with option --http2, but it works fine when I use --http2-prior-knowledge

I have created spring-boot application with tomcat 9.0.16, spring-boot 2.1.3.RELEASE, JDK1.8.
When I am making curl post request with --http2 its saying "curl: (56) Recv failure: Connection reset by peer".
but when I use --http-prior-knowledge it works fine.
my application.property file
server.port=8080
server.http2.enabled=true
and congif file
#Bean
public WebServerFactoryCustomizer tomcatCustomizer() {
return (container) -> {
if (container instanceof TomcatServletWebServerFactory) {
((TomcatServletWebServerFactory) container)
.addConnectorCustomizers((connector) -> {
connector.addUpgradeProtocol(new Http2Protocol());
});
}
};
}
for curl -vvv --http2 -H 'Content-Type: application/json' -H 'cache-control: no-cache' -XPOST http://localhost:8080/save -d '{"xyz":"xyz"}'
logs of curl->
* Trying ::1...
* TCP_NODELAY set
* Expire in 150000 ms for 3 (transfer 0x7fc78a808a00)
* Expire in 200 ms for 4 (transfer 0x7fc78a808a00)
* Connected to localhost (::1) port 8080 (#0)
> POST /save HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.64.0
> Accept: */*
> Connection: Upgrade, HTTP2-Settings
> Upgrade: h2c
> HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA
> Content-Type: application/json
> Postman-Token: 52e0708b-ce97-4baa-a567-2dabc675f3dd
> cache-control: no-cache
> Content-Length: 702
>
* upload completely sent off: 702 out of 702 bytes
< HTTP/1.1 101
< Connection: Upgrade
< Upgrade: h2c
< Date: Wed, 27 Mar 2019 12:29:18 GMT
* Received 101
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Connection state changed (MAX_CONCURRENT_STREAMS == 200)!
* Recv failure: Connection reset by peer
* Failed receiving HTTP2 data
* Send failure: Broken pipe
* Failed sending HTTP2 data
* Connection #0 to host localhost left intact
curl: (56) Recv failure: Connection reset by peer
curl -vvv --http2-prior-knowledge -H 'Content-Type: application/json' -H 'Postman-Token: 52e0708b-ce97-4baa-a567-2dabc675f3dd' -H 'cache-control: no-cache' -XPOST http://localhost:8080/save -d '{"xyz":"xyz"}'
* Expire in 0 ms for 6 (transfer 0x7fc5c0808a00)
* Trying ::1...
* TCP_NODELAY set
* Expire in 150000 ms for 3 (transfer 0x7fc5c0808a00)
* Expire in 200 ms for 4 (transfer 0x7fc5c0808a00)
* Connected to localhost (::1) port 8080 (#0)
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7fc5c0808a00)
> POST /save HTTP/2
> Host: localhost:8080
> User-Agent: curl/7.64.0
> Accept: */*
> Content-Type: application/json
> Postman-Token: 52e0708b-ce97-4baa-a567-2dabc675f3dd
> cache-control: no-cache
> Content-Length: 702
>
* We are completely uploaded and fine
* Connection state changed (MAX_CONCURRENT_STREAMS == 200)!
< HTTP/2 200
< content-type: application/json;charset=UTF-8
< date: Wed, 27 Mar 2019 12:32:26 GMT
<
* Connection #0 to host localhost left intact
true%
You cannot use a POST method to perform an HTTP/1.1 upgrade, so Tomcat is probably choking on your first request (curl --http2 ...) for that reason.
I am the HTTP/2 implementer in Jetty, and Jetty also does not upgrade to HTTP/2 in that case, although it responds with HTTP/1.1 200 to the request, rather than choking.
Converting the first request to a GET without content, the upgrade succeeds in Jetty with a HTTP/1.1 101 response, as expected.
The second request is not an HTTP/1.1 upgrade, but a prior knowledge HTTP/2 request; there is no upgrade and therefore no limitation as to what HTTP method you can use, so the request succeeds in both Jetty and Tomcat.

Jenkins pipeline not finish tomcat war deploy

I want to deploy a war from Jenkins using Tomcat manager.
Here is what i am doing from command line :
curl -v -u user:pasword -T target/app.war "http://host:8180/manager/text/deploy?path=&update=true"
It takes a little bit time and works :
* Hostname was NOT found in DNS cache
* Trying ip...
* Connected to host.com (ip) port 8180 (#0)
* Server auth using Basic with user 'jenkins'
> PUT /manager/text/deploy?path=&update=true HTTP/1.1
> Authorization: Basic amVua2luczpLbzNEaUE=
> User-Agent: curl/7.38.0
> Host: host.com:8180
> Accept: */*
> Content-Length: 71682391
> Expect: 100-continue
>
< HTTP/1.1 100
* We are completely uploaded and fine
< HTTP/1.1 200
< Cache-Control: private
< Expires: Thu, 01 Jan 1970 00:00:00 UTC
< Content-Type: text/plain;charset=utf-8
< Transfer-Encoding: chunked
< Date: Tue, 14 Aug 2018 13:18:22 GMT
<
OK - Application déployée pour le chemin de contexte [/]
* Connection #0 to host host.com left intact
My problem is when i am execute this command in Jenkins Pipeline :
stage('Tomcat Deploy') {
sh "curl -v -u user:password -T app.war http://host:8180/manager/text/deploy?path=&update=true"
}
The curl command is not finished correctly :
+ curl -v -u jenkins:pass -T app.war http://host:8180/manager/text/deploy?path=
* Hostname was NOT found in DNS cache
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying ip...
* Connected to host.com (ip) port 8180 (#0)
* Server auth using Basic with user 'jenkins'
> PUT /manager/text/deploy?path= HTTP/1.1
> Authorization: Basic amVua2luczpLbzNEaUE=
> User-Agent: curl/7.38.0
> Host: host.com:8180
> Accept: */*
> Content-Length: 71682391
> Expect: 100-continue
>
< HTTP/1.1 100
} [data not shown]
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
And it goes to the next stage without waiting the curl deploy result. Is there any quick solution to fix that?
Yes the war was not uploaded. But i resolved my problem using --upload-file option. Now Jenkins wait for upload as attended. Thank you.
A quick(but very bad) fix for this would be to put a sleep for some time in your code.
sleep(30)
This will give curl commad time to submit/upload your jar to your target server. ** Dont rely on this in Production **

Curl build with bash script

I want to create curl with #!/bin/sh script and the part that giving me a headache is:
STR="-XGET -v -H 'Authorization: Bearer "$TOKEN"' https://my_endpoint/sth?"
echo $STR
CON="$(curl $STR)"
The echo there is:
-XGET -v -H 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJleHAiOjE0NTM5NzIxODcsInVzZXJuYW1lIjoid2luZ3UtY2xpZW50LWFkbWluQHNwZWljaGVyMjEwLmNvbSIsImlhdCI6IjE0NTM4ODU3ODcifQ.ADLcrV4yph6owwgMLak2RsnC95WK17ULflCisvNWBkeA93G4WUQ-BMrjnhQeuIgSfxSYnAmgmI36ggc2PytWhkqk8lIYrMJTH80tggBYCnnuA2lM26IZ2ViUMK1cj-BH3-dh4HmqSm_hozAFnVqGQi9P5J4CBz8eCf_mKc3iq-7EnXRikTkgakF69-jPfFA_9yO26JzZeDpymowa-LRPafWPtYinzmkaUQ2SHjUdWtGmELAyzkGUOOXrZ8TgvV9Yeb-OnEoY54GRSlb4ogVzAwWCJ2Y6vxmvNpAN5wiUZMylqTGhnqFr9MOp4JId1RavjwT7STRp9bCHBxD55CtYoEQ-oSpDv6WkgB07CtCRi0Spx9ErVsaB0Xf1mH9XKAVjOQ_dNNpKTxlqIXMbbosxEhjYE9K6Z30c3uWhCgccNdEEHxPhi7d2bRO3M_3fJPKsYWWk5DXhxmkFpJ4fLf05JO31FFIoj8q7H3c5NEvXVk_keS-jPY5iP5xRY1dv9P8bWPEwFk1-qQrXZ1mMNiLDLxdB9cXE9Tm6Eo4Rxo71H2o4Z1DHmnVHHctsATzywsJIe3o8Ym5o0OsmS3WH3EJ-IS572lFv-ZQSkt3fq927JlvWotd9HHMT2MOPf8Zg5cdNd-hclZUfj7qOi-a0Afbn2cT3FccBXJ8l4' https://my_endpoint/sth?
And when i copy this from terminal and paste it into curl it works, but in the verbose log I find:
-XGET -v -H 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJleHAiOjE0NTM5NzIxODcsInVzZXJuYW1lIjoid2luZ3UtY2xpZW50LWFkbWluQHNwZWljaGVyMjEwLmNvbSIsImlhdCI6IjE0NTM4ODU3ODcifQ.ADLcrV4yph6owwgMLak2RsnC95WK17ULflCisvNWBkeA93G4WUQ-BMrjnhQeuIgSfxSYnAmgmI36ggc2PytWhkqk8lIYrMJTH80tggBYCnnuA2lM26IZ2ViUMK1cj-BH3-dh4HmqSm_hozAFnVqGQi9P5J4CBz8eCf_mKc3iq-7EnXRikTkgakF69-jPfFA_9yO26JzZeDpymowa-LRPafWPtYinzmkaUQ2SHjUdWtGmELAyzkGUOOXrZ8TgvV9Yeb-OnEoY54GRSlb4ogVzAwWCJ2Y6vxmvNpAN5wiUZMylqTGhnqFr9MOp4JId1RavjwT7STRp9bCHBxD55CtYoEQ-oSpDv6WkgB07CtCRi0Spx9ErVsaB0Xf1mH9XKAVjOQ_dNNpKTxlqIXMbbosxEhjYE9K6Z30c3uWhCgccNdEEHxPhi7d2bRO3M_3fJPKsYWWk5DXhxmkFpJ4fLf05JO31FFIoj8q7H3c5NEvXVk_keS-jPY5iP5xRY1yirgabLv9P8bWPEwFk1-qQrXZ1mMNiLDLxdB9cXE9Tm6Eo4Rxo71H2o4Z1DHmnVHHctsATzywsJIe3o8Ym5o0OsmS3WH3EJ-IS572lFv-ZQSkt3fq927JlvWot5MN9HHMT2MOPf8Zg5c6udNd-hclZUfj7qOi-a0Afbn2cT3FccBXJ8l4' https://my_endpoint/sth?
* Rebuilt URL to: Bearer/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Could not resolve host: Bearer
* Closing connection 0
curl: (6) Could not resolve host: Bearer
* Rebuilt URL to: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJleHAiOjE0NTM5NzIxODcsInVzZXJuYW1lIjoid2luZ3UtY2xpZW50LWFkbWluQHNwZWljaGVyMjEwLmNvbSIsImlhdCI6IjE0NTM4ODU3ODcifQ.ADLcrV4yph6owwgMLak2RsnC95WK17ULflCisvNWBkeA93G4WUQ-BMrjnhQeuIgSfxSYnAmgmI36ggc2PytWhkqk8lIYrMJTH80tggBYCnnuA2lM26IZ2ViUMK1cj-BH3-dh4HmqSm_hozAFnVqGQi9P5J4CBz8eCf_mKc3iq-7EnXRikTkgakF69-jPfFA_9yO26JzZeDpymowa-LRPafWPtYinzmkaUQ2SHjUdWtGmELAyzkGUOOXrZ8TgvV9Yeb-OnEoY54GRSlb4ogVzAwWCJ2Y6vxmvNpAN5wiUZMylqTGhnqFr9MOp4JId1RavjwT7STRp9bCHBxD55CtYoEQ-oSpDv6WkgB07CtCRi0Spx9ErVsaB0Xf1mH9XKAVjOQ_dNNpKTxlqIXMbbosxEhjYE9K6Z30c3uWhCgccNdEEHxPhi7d2bRO3M_3fJPKsYWWk5DXhxmkFpJ4fLf05JO31FFIoj8q7H3c5NEvXVk_keS-jPY5iP5xRY1yirgabLv9P8bWPEwFk1-qQrXZ1mMNiLDLxdB9cXE9Tm6Eo4Rxo71H2o4Z1DHmnVHHctsATzywsJIe3o8Ym5o0OsmS3WH3EJ-IS572lFv-ZQSkt3fq927JlvWot5MN9HHMT2MOPf8Zg5c6udNd-hclZUfj7qOi-a0Afbn2cT3FccBXJ8l4'/
* Could not resolve host: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJleHAiOjE0NTM5NzIxODcsInVzZXJuYW1lIjoid2luZ3UtY2xpZW50LWFkbWluQHNwZWljaGVyMjEwLmNvbSIsImlhdCI6IjE0NTM4ODU3ODcifQ.ADLcrV4yph6owwgMLak2RsnC95WK17ULflCisvNWBkeA93G4WUQ-BMrjnhQeuIgSfxSYnAmgmI36ggc2PytWhkqk8lIYrMJTH80tggBYCnnuA2lM26IZ2ViUMK1cj-BH3-dh4HmqSm_hozAFnVqGQi9P5J4CBz8eCf_mKc3iq-7EnXRikTkgakF69-jPfFA_9yO26JzZeDpymowa-LRPafWPtYinzmkaUQ2SHjUdWtGmELAyzkGUOOXrZ8TgvV9Yeb-OnEoY54GRSlb4ogVzAwWCJ2Y6vxmvNpAN5wiUZMylqTGhnqFr9MOp4JId1RavjwT7STRp9bCHBxD55CtYoEQ-oSpDv6WkgB07CtCRi0Spx9ErVsaB0Xf1mH9XKAVjOQ_dNNpKTxlqIXMbbosxEhjYE9K6Z30c3uWhCgccNdEEHxPhi7d2bRO3M_3fJPKsYWWk5DXhxmkFpJ4fLf05JO31FFIoj8q7H3c5NEvXVk_keS-jPY5iP5xRY1yirgabLv9P8bWPEwFk1-qQrXZ1mMNiLDLxdB9cXE9Tm6Eo4Rxo71H2o4Z1DHmnVHHctsATzywsJIe3o8Ym5o0OsmS3WH3EJ-IS572lFv-ZQSkt3fq927JlvWot5MN9HHMT2MOPf8Zg5c6udNd-hclZUfj7qOi-a0Afbn2cT3FccBXJ8l4'
* Closing connection 1
curl: (6) Could not resolve host: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJleHAiOjE0NTM5NzIxODcsInVzZXJuYW1lIjoid2luZ3UtY2xpZW50LWFkbWluQHNwZWljaGVyMjEwLmNvbSIsImlhdCI6IjE0NTM4ODU3ODcifQ.ADLcrV4yph6owwgMLak2RsnC95WK17ULflCisvNWBkeA93G4WUQ-BMrjnhQeuIgSfxSYnAmgmI36ggc
* Trying 54.228.198.226...
* Connected to my_endpoint (54.228.198.226) port 443 (#2)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: *.herokuapp.com
* Server certificate: DigiCert SHA2 High Assurance Server CA
* Server certificate: DigiCert High Assurance EV Root CA
> GET /api/sth? HTTP/1.1
> Host: my_endpoint/sth?
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 401 Unauthorized
< Connection: keep-alive
< Server: nginx/1.8.0
< Content-Type: application/json
< Transfer-Encoding: chunked
< X-Powered-By: PHP/5.6.17
< Cache-Control: no-cache
< Allow: GET
< Date: Wed, 27 Jan 2016 09:09:49 GMT
< Via: 1.1 vegur
<
{ [59 bytes data]
100 48 0 48 0 0 41 0 --:--:-- 0:00:01 --:--:-- 0
* Connection #2 to host my_endpoint left intact
What's wrong with that header?
Use an array to store command arguments.
curl_options=(-XGET -v -H "Authorization: Bearer $TOKEN" "https://my_endpoint/sth?")
content=$(curl "${curl_options[#]}")
You can use
eval curl $STR "https://my_endpoint" > 'output_file'

Resources