how to pass the cookies in the curl request - node.js

I have to send request using curl, in that request i needs to set the cookie from the below response.
So can some one help me how to pass all the cookies in the curl request
HTTP/1.1 200 OK
X-Powered-By: Express
Access-Control-Allow-Origin:undefined
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET,POST,OPTIONS
Access-Control-Allow-Headers: Content-Type
set-cookie: SESSIONID=agpuB2CqPDhkupxfbrZXCR; Path=/ABC
set-cookie: bac_cookie=7959aacd5cc48;Domain=abc.com;Expires=Mon, 05-Dec-2016 18:47:42 GMT; Path=/
set-cookie: beID=0023T21; Domain=abc.com; Expires=Mon,05-Dec-2016 18:47:42 GMT; Path=/
set-cookie:USER_JSESSIONID=agpuB2CqPDhkupxfbrJlbXF3;Domain=abc.com;Expires=Mon, 05-Dec-2016 18:47:42 GMT; Path=/
set-cookie:bac_user_info="UserName|UserLName|UserMailId"; Version=1;Domain=abc.com; Max-Age=3600; Path=/
set-cookie: beID=0023T21; Domain=abc.com; Expires=Mon, 05-Dec-2016 18:47:42 GMT; Path=/
set-cookie:NSC_WB2-CF-8080=ffffffff09ae530a45525d5f4f58455e445a4a4229a0;path=/;httponly
Content-Type: application/json; charset=utf-8
Content-Length: 131
ETag: W/"83-+Jfk31hxbwmLWd1hTlIO1Q"
Date: Mon, 05 Dec 2016 17:47:42 GMT
Connection: abc

If you want to send multiple cookies, just sepreate them by ;
curl -v --cookie "TOKEN1=Yes;TOKEN2=no" http://127.0.0.1:5000

Related

Cookies conversion in Node.js

HI Guys Need a help in cookies
In one Login call i am getting this Cookie as response header but i need the format which is below for next requests:
Response header which i am getting [ 'ApplicationGatewayAffinityCORS=c26d807e1aaeccd5aadfffc649b97688; Path=/; SameSite=None; Secure',
'ApplicationGatewayAffinity=c26d807e1aaeccd5aadfffc649b97688; Path=/',
'.DWPLATFORMAUTH=; expires=Wed, 29-Apr-2020 13:39:20 GMT; path=/DocuWare/Platform; HttpOnly',
'.DWPLATFORMAUTH=BF0F76C29D2A57BBEC15244114BCE0ED2F81AF852C177C8C250C254F40454EAD1341AFAC394F9BF3261EC948C11D709CEBFE08F9F9683FCCB6BB9B7A56EE8C00BE3FDEEF5A9CA56BD9ABEAA651F7A5189698CEDFAAB3F29D1A46BD33E3FA1D692080B1DE68EA4C3A77BB7E9DE26B8F43ABB25575F6A40B223D55EACAA18DF365B98E88CC81D52098126E4FCC4DBF0C19768A1B100D50D0571EE65FF91BCD70CC23CAFEE3F484838AF70A7C995C89DC91CAC34F7A319F589DF00D534BDDF0D9E83791015969D532649981731E667D39A2D3F5D398CDF442E9FB65309282525CECC0BD01806B5CE4FA342A09F06D53E5D95A525470A323667463501EA105D5AD17B6D78EB27C5CEA047511BC55D55F2F2B34D5B196FAB5C69D07971435531CD786E324C2DA1EDEFE8509C863D7751D983A9EAE5BCDBB6556C0634E367BFDCA639FF2A6A56640D4E4D56FF92C4F5CB0CE083C113F05B537DC55C6C13206D865F9965448E4675D359981BD9E52B2E0A1570F831565B61635B4B5E26BB5E2F4EB890A4FC42E0EBEF4E7885DBA13AC8F0A44A4E91BFD7AB9846A906E449BBCE51AD532; path=/; HttpOnly',
'DWPLATFORMBROWSERID=; expires=Wed, 29-Apr-2020 13:39:20 GMT; path=/DocuWare/Platform; HttpOnly',
'DWPLATFORMBROWSERID=FF3A3868BB062A8E1C06EA73E419443B8DC6F073D8C3A8A3988AA9CC808C8FF369099345538486B3FA99DFEC097533BBBD621A12C12E0522521846D2D953F6D2C41DC91EAFFE3A442BC3DA738324F9A063DB88695243E19934325806DBF12D7579CA3BCCFF252A276F68334BD000358948860B23976C81326D8E571B0862045760C5B6FB9115C4F7715E951EC6AE0B779E017433676EAE7D7D202E9EE2ED83C1614317CE122828FF5D980BED4D57524F3BABF60AFFC70EA09D02E0001DD1603B952B03FE3436831E7E148EF1C76BB9A3B6F14940CFAA918A183664A586D049ED; expires=Fri, 30-Apr-2021 13:39:20 GMT; path=/; HttpOnly' ]
**but other request are accepting cookies in this format Which i need **:
'ApplicationGatewayAffinityCORS=71020739a3120956b31575e6a26cf347; ApplicationGatewayAffinity=71020739a3120956b31575e6a26cf347; .DWPLATFORMAUTH=22A566AC0C55B15C492B4CE3EEEFFB667BA0EA95DDA27084A8279F907AB2A475AF44E0D62C4733456628056F3F1E23AE8D60682A4305E8A43B95BC5F9A9A2B02B36B64892DAD484AE7C9C93430AE4B2276E591B2F9D0BCB33FBC14D3A5BF28951996029A55DD5C6B40630838A7A0770472FE8070CF546BF04AA7B31B6E4AD170C0A83FCDC253979084DAD5F23AE6B2DDEB9CF31968D67EBF1CA992B9B5FBFAA1BB3E59AF5F5E4A6D1F1CFFAFFC228CBA03561F60CAA0C47B4C01DA01909433ADF7132C114D98D36114976B9D31E669100EBF73F862ACA81781212819CB6D36A909D4BA9AB856F63B46EF95580A828AE9AB7E61C62F4C6DE925579B325330A6E77E786F0ACEF9C815B0559A7C5AAA12C733D1CE5A4B32ADF1919475C4C1451B304F4A778BD9DE4DD7B2BCCB30C159D503A634F8DA67308441C7A8B8B9B313CEED8C6EFACD20947670546C0EBCE4CC89498AD20CF566062128464077B6A7C12C77B0526F93AD7A6A2BD738C8A2CCAD8D864E23C11E2D0E036DF37E6A00E234B9B545B033929FB2ADB5880D4B8CF7D685ADB340083FFD671704A18259D6F9CD1C96; DWPLATFORMBROWSERID=D95CC701A52B6A15866C5A3966734BD6CF400DB18961F0E8FDA9B7D0F221544DC1D48799617FADC4CDA8F52CC5EBED9F1F8ECAB3969BA913E9DD3B2C346AB09E4083BABC307A4D41B0F3C436BCC5CBD2AC159480E5A48E7101B6BA0442F192B3AF38C00ECF9F3262FCFA911CF1EAF42BACAE869CCB176E49978860225D0FD614D4C2AA9B2BDE9CD376FBFFC16462622CB5235FF9D1F6DE2DDB2F4DADD2CA4497AE388C1745B12D7133FCCE0CF7A11292F49C33DDB25268C44C75C94BB381F2530D820A2FD886F5D36C1A853ECD84136B2541605C85C79C40DB73AF85DDA7701C'

Getting Error while opening hosted KaiOS app

I have a manifest.webapp hosted at my application root (https://localhost:5001/manifest.webapp), when I open it in KaiOS simulator, I get the following error:
Unable to access the app starting document https://localhost:5001/,
got HTTP code 405
Curl of its response is:
HTTP/1.1 200 OK
Date: Wed, 02 Oct 2019 21:18:41 GMT
Content-Type: application/x-web-app-manifest+json
Content-Length: 6097
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Last-Modified: Tue, 01 Oct 2019 07:35:10 GMT
Accept-Ranges: bytes
ETag: "1d5782ac10b5cd1"
Set-Cookie: ClientId=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; samesite=lax
Set-Cookie: ClientId=922A46E87C9646C18555E7E7DE84840F; expires=Mon, 02 Oct 2119 21:18:42 GMT; path=/; samesite=lax
Access-Control-Allow-Origin: *
x-frame-options: allow-from https://example.com/
x-web-server-version: 1.0.0.0
x-besku: UNKNOWN
{
"name": "abc",
"short_name": "abc",
"icons": [..],
"scope": "/",
"start_url": "/abc/?start_url=sss",
"display": "standalone",
"background_color": "#ffffff",
"theme_color": "#0078d7"
...
Any help would be appreciated.
Firefox os/kaios makes a HEAD call, before GET, so that should be implemented on your server, else this error will come.

How do I download an mp3 file with Python3

I am trying to download some playlists off soundcloud and found a site that does this for you. Of course if the playlist is long, then it's super tedious to click each link to download. So I saved the HTML of the page and have parsed out the links. The idea is to use urllib or requests to download the files.
Here's my code:
opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
urllib.request.install_opener(opener)
track_url = 'https://scdownloader.io/download?track=zandex-hazerback-erox-stroke-bth-release&token=be1bc7997695495f756312886f566110'
track_name = 'BANG_THE_HOUSE___zandex-hazerback-erox-stroke-bth-release.mp3'
output_file = '/Users/ms/Desktop/playlist/{}'.format(track_name)
urllib.request.urlretrieve(track_url, output_file)
When I run the above code, it does save the file, but it arrives as a 1 byte file only.
I've tried other permutations using requests but basically either it doesn't work, downloads and saves a zero byte file, or does work to download and save a 1 byte file... just can't get the whole thing!
Also note, I have to send headers b/c otherwise I get a 403 error.
Any help is greatly appreciated!
Thank you!
EDIT:
Per the comments below, here's what the urlretrieve http response is:
Date: Fri, 15 Mar 2019 23:52:44 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: close
Set-Cookie: __cfduid=dcc5f95391fac83973cc77648c0e8c0391552693964; expires=Sat, 14-Mar-20 23:52:44 GMT; path=/; domain=.scdownloader.io; HttpOnly; Secure
X-Powered-By: PHP/5.6.36
Set-Cookie: PHPSESSID=fsnrrrtpnrav3vq5u2t9vfvrp7; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding,User-Agent
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 4b82671d38067790-LAX

Where's the Correlation ID in the Graph API Response?

I'm trying to provide the correlation id for this issue but I'm not sure how to obtain it. I assume it should be in response, is that correct? Is it the client-request-id maybe?
HTTP Response
HTTP/1.1 403 Forbidden
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.5
ocp-aad-diagnostics-server-name: CGa9FFPZASZM+usTGvTzaOZ4zSMxhpbWh2mO9+eJZWs=
request-id: 6ddd7a86-02c9-4dcf-9932-b17afc976107
client-request-id: 50478d75-542d-4e0e-96d9-de913d632471
x-ms-dirapi-data-contract-version: 1.6
ocp-aad-session-key: some-really-long-value
X-Content-Type-Options: nosniff
DataServiceVersion: 3.0;
Strict-Transport-Security: max-age=31536000; includeSubDomains
Access-Control-Allow-Origin: *
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Duration: 782602
X-Powered-By: ASP.NET
Date: Wed, 09 Aug 2017 14:22:21 GMT
Content-Length: 139
{"odata.error":{"code":"Authorization_RequestDenied","message":{"lang":"en","value":"Insufficient privileges to complete the operation."}}}
Token Request Response
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.5
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
client-request-id: 8c500700-b75c-403a-a2c9-c6dfa27049d3
x-ms-request-id: 75627b63-fbd6-4fa8-95b5-b6a325d60900
P3P: CP="DSP CUR OTPi IND OTRi ONL FIN"
Set-Cookie: esctx=some-value; domain=.login.microsoftonline.com; path=/; secure; HttpOnly
Set-Cookie: x-ms-gateway-slice=006; path=/; secure; HttpOnly
Set-Cookie: stsservicecookie=ests; path=/; secure; HttpOnly
X-Powered-By: ASP.NET
Date: Wed, 09 Aug 2017 18:33:33 GMT
Content-Length: 1437
{"token_type":"Bearer","expires_in":"3599","ext_expires_in":"262800","expires_on":"1502307214","not_before":"1502303314","resource":"https://graph.windows.net/","access_token":"some-token-value"}
The correlation ID (also called client-request-id) can be found in interactions with the Azure AD service.
The request immediately before this when you were asking the Azure AD endpoints for tokens will include the ID in the response.
https://login.microsoftonline.com/...
https://login.windows.net/...

VBA WinHTTP to login into Oddsportal

I am trying to login into oddsportal through a VBA script. I have written the following code but it is not working. I am getting an error when I am truing to set cookie for POST request. I would be thankful if someone could point me in the right direction.
Dim WHTTP As Object
Dim myuser, mypass, url, strAuthenticate As String
Dim out As String
url = "http://www.oddsportal.com/"
myuser = "user"
mypass = "pass"
strAuthenticate = "login-username=" & myuser & "&login-password=" & mypass & "&login-submit="
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
WHTTP.Open "POST", url, False
WHTTP.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36"
WHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
WHTTP.setRequestHeader "Connection", "keep-alive"
WHTTP.send strAuthenticate
strCookie = WHTTP.getResponseHeader("Set-Cookie") **'I am getting an error here**
strResponse = WHTTP.ResponseText
WHTTP.Open "GET", "http://www.oddsportal.com/soccer/africa/africa-cup-of-nations/results/", False
WHTTP.setRequestHeader "Connection", "keep-alive"
WHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
WHTTP.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36"
WHTTP.setRequestHeader "Cookie", strCookie
WHTTP.send
out = WHTTP.ResponseText
I changed the authentication method to server based using setcredential method. Now I am able to set cookie from the first part. However, I am still unable to get the data from second page (second part of the code). Here are the response headers that I got using setcredentials: My set cookie line is only able to retain the last cookie.
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection: keep-alive
Date: Tue, 27 May 2014 16:01:29 GMT
Pragma: no-cache
Transfer-Encoding: chunked
Content-Type: text/html
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Age: 0
Server: Apache
Set-Cookie: op_lang=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/
Set-Cookie: op_oddsportal=fehof62734n35crjd9vpshhf10; path=/
Set-Cookie: op_cookie-test=ok; expires=Wed, 27-May-2015 16:01:28 GMT; path=/
Set-Cookie: op_state=1
Set-Cookie: op_last_id=1; expires=Thu, 26-Jun-2014 16:01:28 GMT; path=/
Set-Cookie: op_cookie-test=ok; expires=Wed, 27-May-2015 16:01:28 GMT; path=/
Vary: Accept-Encoding
X-Deliver: Tue, 27 May 2014 16:01:29 GMT
This is cookie that I get from Fiddler:
Set-Cookie:op_user_logout=0; expires=Mon, 18-May-2015 18:44:49 GMT; path=/
Set-Cookie:op_last_id=1; expires=Thu, 26-Jun-2014 18:44:49 GMT; path=/
Set-Cookie:op_user_login_id=95774; expires=Mon, 18-May-2015 18:44:49 GMT; path=/
Set-Cookie:op_user_login_hash=73a967ad18d6a353afa12877309f4708; expires=Mon, 18-May-2015 18:44:49 GMT; path=/
Set-Cookie:op_cookie-test=ok; expires=Wed, 27-May-2015 18:44:48 GMT; path=/
Set-Cookie:op_user_time_zone=1.00; expires=Thu, 26-Jun-2014 18:44:49 GMT; path=/
Set-Cookie:op_user_full_time_zone=35; expires=Thu, 26-Jun-2014 18:44:49 GMT; path=/
Set-Cookie:op_lang=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/
I'm not sure it will help in this specific case, but request and response cookies handling is included in my library Excel-REST. Here's an example of getting and setting the login id and hash:
Dim OddsClient As New RestClient
OddsClient.BaseUrl = "http://www.oddsportal.com/"
Dim LoginRequest As New RestRequest
LoginRequest.Method = httpPOST
LoginRequest.Format = formurlencoded
LoginRequest.AddParameter "login-username", myuser
LoginRequest.AddParameter "login-password", mypass
LoginRequest.AddParameter "login-submit", ""
Dim LoginResponse As RestResponse
Set LoginResponse = OddsClient.Execute(LoginRequest)
If LoginResponse.StatusCode = 200 Then
Dim OddsRequest As New RestRequest
OddsRequest.Resource = "soccer/africa/africa-cup-of-nations/results/"
OddsRequest.AddCookie "op_user_login_id", LoginResponse.Cookies("op_user_login_id")
OddsRequest.AddCookie "op_user_login_hash", LoginResponse.Cookies("op_user_login_hash")
Dim OddsResponse As RestResponse
Set OddsResponse = OddsClient.Execute(OddsRequest)
End If
I had some difficulty retrieving cookies from headers, since every cookie has the same header key, "Set-Cookie". In Excel-REST I split getAllResponseHeaders into a Collection of key-value headers for ease of access and then pulled out those with the "Set-Cookie" key (See RestHelpers). For your example, something similar to the following may work:
Dim Headers As Collection ' of Dictionaries with key, value
Set Headers = ExtractHeadersFromResponseHeaders(WHTTP.getAllResponseHeaders) ' from RestHelpers
' Setup GET...
Dim Header As Dictionary
For Each Header In Headers
' Move all cookies from login to GET request
If Header("key") = "Set-Cookie" Then
WHTTP.setRequestHeader "Cookie", Header("value")
End If
Next Header

Resources