How to repeat https request with curl? - ssl

I have the following data captured:
POST /AppHTTP.php HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 89
Host: parkingcab.mos.ru
Connection: Keep-Alive
Accept-Encoding: gzip
User-Agent: App: 4.6() / OS: 7.1.1 / Device: Sony
format=json&appVersion=3&phoneNo=79161234567&PIN=1234&operation=file_list&partnerID=Qulix
HTTP/1.1 200 OK
Date: Sat, 27 Jan 2018 09:57:26 GMT
Server: Apache
Cache-Control: max-age=2592000
Expires: Mon, 26 Feb 2018 09:57:26 GMT
Content-Length: 192
Connection: close
Content-Type: application/json; charset="utf-8"
{"status":1,"operation":"file_list","version":"2.6","response":{"files":[{"file":{"id":"2533922","name":"news.xml","time":"1516885837","type":"text\/xml","partner":"Qulix"}}],"language":"ru"}}
I try to repeat with curl -
curl -vvvv --request POST --header "Content-Type: application/x-www-form-urlencoded" --header "User-Agent: App: 4.6() / OS: 7.1.1 / Device: Sony" --header "Host: pаrkingcаb.mоs.ru" --header "Connection: Keep-Alive" --header "Accept-Encoding: gzip" "https://pаrkingcаb.mоs.ru/AppHTTP.php?format=json&appVersion=3&phoneNo=79161234567&PIN=1234&operation=file_list&partnerID=Qulix"
but I get 503 / No operation response. I also tried to pass data as payload:
curl -vvvv --request POST --header "Content-Type: application/x-www-form-urlencoded" --header "User-Agent: App: 4.6() / OS: 7.1.1 / Device: Sony" --header "Host: pаrkingcаb.mоs.ru" --header "Connection: Keep-Alive" --header "Accept-Encoding: gzip" -d "{'format': 'json', 'appVersion': '3', 'phoneNo': '79161234567', 'PIN': '1234', 'operation': 'file_list', 'partnerID': 'Qulix'}" "https://pаrkingcаb.mоs.ru/AppHTTP.php"
But it didn't help. What am I missing?

You'll like h2c.
If you paste your HTTP request into that, it gives you this curl command line:
curl --header Accept: --compressed --header "Connection: Keep-Alive" --user-agent "App: 4.6() / OS: 7.1.1 / Device: Sony" --data-binary "format=json&appVersion=3&phoneNo=79161234567&PIN=1234&operation=file_list&partnerID=Qulix" https://pаrkingcаb.mоs.ru/AppHTTP.php

Related

curl, API request works in Insomnia, but not in generated code for curl

I have request in Insomnia. When I send it via Insomnia, no problemo. But when I generate source code for curl, it shows me this.
curl --request POST \
--url URL \
--header 'Authorization: bearer XXX' \
--header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \
--cookie JSESSIONID=XXX \
--form datasetFile=#FOLDER/producthierarchyl1-1.zip
{"message":"Bad Request","logref":null,"path":null,"_embedded":{"errors":[{"message":"Required argument [Publisher datasetFile] not specified","logref":null,"path":"/datasetFile","_embedded":{},"_links":{}}]},"_links":{"self":{"href":"/data-api/public-api/v4/datasets/ingestion/","templated":false,"profile":null,"deprecation":null,"title":null,"hreflang":null,"type":null,"name":null}}}
Insomnia output is like this.
> POST PATH HTTP/2
> Host: URL
> user-agent: insomnia/2022.3.0
> cookie: JSESSIONID=XXX
> authorization: bearer XXX
> content-type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY
> accept: */*
> content-length: 407
* STATE: DO => DID handle 0x170404b14008; line 2077 (connection #27)
* multi changed, check CONNECT_PEND queue!
* STATE: DID => PERFORMING handle 0x170404b14008; line 2196 (connection #27)
| --X-INSOMNIA-BOUNDARY
| Content-Disposition: form-data; name="datasetFile"; filename="producthierarchyl1-1.zip"
| Content-Type: application/zip
| PK�QU�}�%+producthierarchyl1-1.csvUT բ�b
| --X-INSOMNIA-BOUNDARY--
* We are completely uploaded and fine
* HTTP/2 found, allow multiplexing
Where is the catch?
Thanks.
Remove the --header 'content-type: multipart/form-data; boundary=---011000010111000001101001 option.
It really should not be used like this: curl manages that header and the boundary on its own so changing it should only be done in the rare event you truly want and need to fiddle around with it.
A more minor second thing: --request POST should be dropped from the command line, as it is superfluous and easily cause problems if you add --location later on.
Updated
This flaw is said to have been fixed in a later version of Insomnia
For any folks bumping into this issue again, this answer correctly explains the reason for the problem.
Fortunately this should only be reproducible in versions 2022.3.0 and older versions of Insomnia.
If you use the latest one, 2022.5.1, the generated curl will no longer have this problem, example of a multipart request generated:
curl --request GET \
--url http://mockbin.org/request/anything \
--header 'Content-Type: multipart/form-data' \
--form test=test \
--form test=#/Users/yourUserName/Desktop/somefile.txt

Kibana Rest API redirects to login

I'm new to ElasticSearch and Kibana. I'm trying to use Kibana's REST API, but the response i get are redirections to /login whatever the request i try.
The basePath has been modified in kibana.yml :
server.basePath: "/demo"
server.rewriteBasePath: true
Every request, such as :
$ curl -v -u user:passwd -X GET "127.0.0.1:5601/demo/api/features"
gets the following response :
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 5601 (#0)
* Server auth using Basic with user 'user'
> GET /demo/api/features HTTP/1.1
> Authorization: Basic xxxxxxxx
> User-Agent: curl/7.38.0
> Host: 127.0.0.1:5601
> Accept: */*
>
< HTTP/1.1 302 Found
< location: /demo/login?nextUrl=/demo/api/features
< kbn-name: kibana
< content-type: text/html; charset=utf-8
< cache-control: no-cache
< content-length: 0
< connection: close
< Date: Thu, 26 Nov 2020 10:32:56 GMT
<
* Closing connection 0
I'm using v7.2.0 with Linux.
Could someone tell me what i'm doing wrong ?
Best regards
The problem came from the use of the plugin readonlyrest.
First, I had to log in and retrieve the cookie, before querying for anything :
curl -v -X POST "127.0.0.1:5601/demo/login" -d "username=user&password=passwd"-H "kbn-xsrf: true" -H 'Accept: application/json' -c cookie.txt
And then use with the cookie :
curl -v -X GET "127.0.0.1:5601/demo/api/features" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -H "Accept: application/json" -b cookie.txt
In more recent versions of Kibana and ROR we can obtain the cookie with:
curl '127.0.0.1:5601/login' -H 'kbn-xsrf: true' -H 'Content-Type: application/json' --data-raw '{"username":"user","password":"password"}' -c cookie.txt

Invalid Document Stream when uploading thumbnail to OneDrive

I download a JPEG thumbnail.
curl -L 'https://api.onedrive.com/v1.0/drive/items/EF393A3B6CA330A3!112/thumbnails/0/small/content' \
-H "Authorization: Bearer $AUTH" \
> image
I then try to use that very same downloaded image as a custom thumbnail.
curl -v 'https://api.onedrive.com/v1.0/drive/items/EF393A3B6CA330A3!112/thumbnails/1/source/content' \
-X PUT -H 'Content-Type: image/jpeg' -H "Authorization: Bearer $AUTH" \
-d #image
but it doesn't work.
< HTTP/1.1 400 Bad Request
< Via: 1.1 BY3302____PAP061 (wls-colorado)
< Content-Length: 71
< Content-Type: application/json
* Server Microsoft-HTTPAPI/2.0 Microsoft-HTTPAPI/2.0 is not blacklisted
< Server: Microsoft-HTTPAPI/2.0 Microsoft-HTTPAPI/2.0
< X-WLSPROXY: BY3302____PAP061
< X-MSNSERVER: DM2301____PAP093
< X-QosStats: {"ApiId":0,"ResultType":2,"SourcePropertyId":0,"TargetPropertyId":42}
< X-ThrowSite: 3683.1abb
< X-AsmVersion: UNKNOWN; 19.22.0.0
< P3P: CP="BUS CUR CONo FIN IVDo ONL OUR PHY SAMo TELo"
< Date: Fri, 17 Jul 2015 06:59:24 GMT
<
* Connection #0 to host api.onedrive.com left intact
{"error":{"code":"invalidRequest","message":"Invalid Document Stream"}}
What does OneDrive want me to do to upload the thumbnail?
I looked at the "example", but it didn't shed much light.

cURL hangs at: "no chunk, no close, no size. Assume close to signal end"

When using this command to stream upload to a Apache/PHP server
curl -X POST \
-i --data-binary #customfile.app \
-H "Transfer-Encoding: chunked" \
-H "Content-Type: application/app" \
-H "X-CustomHeader1: customvalue1" \
-H "X-CustomHeader2: customvalue2" \
-H "X-CustomHeader3: customvalue3" \
-H "X-CustomHeader4: customvalue4" \
-H "X-CustomHeader5: customvalue5" \
-H "X-CustomHeader6: customvalue6" \
--ignore-content-length \
--progress-bar -vvv \
http://[DOMAIN]/upload.php
The command hangs as follows:
* Hostname was NOT found in DNS cache
* Trying [IP_ADDRESS]...
* Connected to [DOMAIN] ([IP_ADDRESS]) port 80 (#0)
> POST /upload.php HTTP/1.1
> User-Agent: curl/7.37.1
> Host: [DOMAIN]
> Accept: */*
> Transfer-Encoding: chunked
> Content-Type: application/app
> X-CustomHeader1: customvalue1
> X-CustomHeader2: customvalue2
> X-CustomHeader3: customvalue3
> X-CustomHeader4: customvalue4
> X-CustomHeader5: customvalue5
> X-CustomHeader6: customvalue6
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Content-Type: text/html; charset=UTF-8
Content-Type: text/html; charset=UTF-8
< Date: Thu, 12 Feb 2015 11:10:17 GMT
Date: Thu, 12 Feb 2015 11:10:17 GMT
* Server Apache is not blacklisted
< Server: Apache
Server: Apache
< Vary: Content-Type
Vary: Content-Type
< Content-Length: 0
Content-Length: 0
< Connection: keep-alive
Connection: keep-alive
* no chunk, no close, no size. Assume close to signal end
<
Now, when the no chunk, no close, no size. Assume close to signal end message appears I do a checksum on both the local and server file to prove they are both the same, which they are. Meaning that the file successfully uploads, but for some reason the connection is not closed.
Why is that and how do I resolve it? Can I tell cURL to close the connection when the whole file has been uploaded? Thanks
You specifically tell curl to ignore the content-length set by the server. Because of this the end of the response will be assumed to be connection close. But the server does not close because it waits for more requests.
Apart from that: I don't think you can just add "Transfer-Encoding: chunked" as a custom header. It is not enough to tell the server that the content will be sent in chunks but curl actually has to use chunked encoding which it probably does not.
I had a funny case when this happened with a JSP page.
Flushing a newline helped:
<%
out.println("");
out.flush();
%>

How do I use the Unfuddle API to get files?

I'm new to web programming, as you are about to see.
I'm trying to periodically retrieve files from Unfuddle using their API. I tried their first code example and it seems to return valid information from my HTTP GET call, but I don't know how to use this information to get specific files onto my hard drive. How is this done?
Here is my exact HTTP GET call and response (except for the password being replaced):
bmihura#bmihura-PC ~
$ curl -i -u bmihra:password -X GET \
> -H 'Accept: application/xml' \
> 'http://spowertech.unfuddle.com/api/v1/projects/projects.xml'
HTTP/1.1 302 Found
Server: nginx/1.0.5
Date: Fri, 17 Aug 2012 11:53:23 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.8
Vary: Accept-Encoding
Cache-Control: no-cache
Set-Cookie: authenticated=; domain=.unfuddle.com; path=/; expires=Thu, 01-Jan-19 70 00:00:00 GMT
Set-Cookie: authenticated=false; path=/; expires=Fri, 17-Aug-2012 13:51:24 GMT
Set-Cookie: unfuddle_secure=; domain=.unfuddle.com; path=/; expires=Thu, 01-Jan- 1970 00:00:00 GMT
Set-Cookie: _unfuddle_session=; domain=.unfuddle.com; path=/; expires=Thu, 01-Ja n-1970 00:00:00 GMT
Set-Cookie: _unfuddle_session=BAh7BjoPc2Vzc2lvbl9pZCIlZGIzOTlmMTcxZGIwZjE4MDRhZW RkZGVmOGI4YjIxNzM%3D--0833ed386e5cd62894bb8dd787d856545897df35; path=/; expires= Fri, 17-Aug-2012 13:53:24 GMT; HttpOnly
Location: https://spowertech.unfuddle.com/projects/projects
Content-Length: 115
Status: 302
<html><body>You are being redirected.</body></html>
You need to use https instead of http in the url at the bottom - i.e.
curl -i -u bmihra:password -X GET \
-H 'Accept: application/xml' \
'https://spowertech.unfuddle.com/api/v1/projects/projects.xml'
In addition, to get it to work via my windows machine I had to replace the ' with " in the -H and remove the ' around the url. So I ended up using
curl -i -u bmihra:password -X GET \
-H "Accept: application/xml" \
https://spowertech.unfuddle.com/api/v1/projects/projects.xml
Hope that helps!