postman HSP query failed

241 views
Skip to first unread message

Kai Zhang

unread,
Mar 18, 2018, 5:25:19 AM3/18/18
to A gathering place for the Open Rail Data community
Hi, I'm new with HSP restapi query. 
Testing from POSTMAN, i am gettig 

<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.2.15 (CentOS) Server at hsp-prod.rockshore.net Port 443</address>



The postman code is simply below


POST /api/v1/serviceMetrics HTTP/1.1
Authorization: Basic {Base64("us...@registered.com:PasswordwithSpecialCharacter")}
Content-Type: application/json
Content-Length: 178
Cache-Control: no-cache
Postman-Token: 63802dff-800d-48ba-b1a0-de8fa2114ee1

{
    "from_loc":"WOK",
    "to_loc":"WAT",
    "from_time":"0700",
    "to_time":"0800",
    "from_date":"2018-01-22",
    "to_date":"2018-01-24",
    "days":"WEEKDAY"
}


Would it be possible for someone to tell me what's wrong with the POST query?
Cheers
Kai

Peter Hicks

unread,
Mar 18, 2018, 8:44:39 AM3/18/18
to Kai Zhang, A gathering place for the Open Rail Data community
Hi Kai

Sending the same JSON body as you, I get a 200 response and metrics back.

I think your Base64-encoded username and password is correct - if I change my username or password, I get an HTTP 401.

A strange question, but do you get a JSESSIONID cookie sent back to you?  If so, that indicates authentication is OK, and if not, there's some problem authenticating your request.


Peter


--
You received this message because you are subscribed to the Google Groups "A gathering place for the Open Rail Data community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openraildata-t...@googlegroups.com.
To post to this group, send email to openrail...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


OpenTrainTimes Ltd. registered in England and Wales, company no. 09504022.
Registered office: 13a Davenant Road, Upper Holloway, London N19 3NW

Kai Zhang

unread,
Mar 18, 2018, 1:55:15 PM3/18/18
to A gathering place for the Open Rail Data community
Thanks Peter for the reply. 

I can log in without issue from https://datafeeds.nationalrail.co.uk/#/user with the same username/password.(it's a personal account i registered)

In postman, i did get JSession Cookie, but after a few failed test, i deleted it. it never come back again :(

Not just postman, query via curl gave me the same err;

$ curl -X POST \
>   -H 'Authorization: Basic {Base64(\"Emailwith@character:passwordWith+Symbol\")}' \
>   -H 'Cache-Control: no-cache' \
>   -H 'Content-Length: 178' \
>   -H 'Content-Type: application/json' \
>   -H 'Host: hsp-prod.rockshore.net' \
>   -H 'Postman-Token: 8d352916-2df1-45a8-b953-35728b8dea24' \
>   -d '{
>     "from_loc":"WOK",
>     "to_loc":"WAT",
>     "from_time":"0700",
>     "to_time":"0800",
>     "from_date":"2018-01-22",
>     "to_date":"2018-01-23",
>     "days":"WEEKDAY"
> }'
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.2.15 (CentOS) Server at hsp-prod.rockshore.net Port 443</address>
</body></html>



In your attemtp, how do you handle Authorization header:
 -H 'Authorization: Basic {Base64(\"Emailwith@character:passwordWith+Symbol\")}' \

I tried without space, eg 
 -H 'Authorization: Basic{Base64(\"Emailwith@character:passwordWith+Symbol\")}' \

Still no joy. 

WantStuff

unread,
Mar 18, 2018, 6:37:17 PM3/18/18
to A gathering place for the Open Rail Data community
Is the header “key” correct?
I could be way off and thinking about something else, but shouldn’t the header be ‘X-Auth’ or something?

Peter Hicks

unread,
Mar 18, 2018, 6:49:10 PM3/18/18
to WantStuff, A gathering place for the Open Rail Data community
Nope, it's definitely Authorization, and the header is key, colon, space, and then the value.

I tried the exact same curl as Kai put command, but with my base64-encoded username/password, and I had a successful response.

I tried un-checking the HSP access after logging in to https://datafeeds.nationalrail.co.uk/ and had a 401 Unauthorized.

So, Kai - time to look closer!  Do you get the 400 error straight away, or is there a delay of about 60 seconds before you get the error?


Peter

On Sun, 18 Mar 2018 at 22:37 WantStuff <wants...@gmail.com> wrote:
Is the header “key” correct?
I could be way off and thinking about something else, but shouldn’t the header be ‘X-Auth’ or something?

--
You received this message because you are subscribed to the Google Groups "A gathering place for the Open Rail Data community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openraildata-t...@googlegroups.com.
To post to this group, send an email to openrail...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Kai Zhang

unread,
Mar 21, 2018, 5:05:11 PM3/21/18
to A gathering place for the Open Rail Data community
there is a delay of 60s before I get the error.
With the curl command, did you need to put any space between Basic and { ? I tried both, either works. 
Also I tried to remove \ before ", same issue


$ date 
Wed 21 Mar 20:58:38 GMT 2018
andrew@andrew-SVF1521A1EW:~$ curl -X POST \
>   -H 'Authorization: Basic {Base64(\"mye...@registered.com\":\"Maya4pro+\")}' \
>   -H 'Cache-Control: no-cache' \
>   -H 'Content-Length: 178' \
>   -H 'Content-Type: application/json' \
>   -H 'Host: hsp-prod.rockshore.net' \
>   -d '{
>     "from_loc":"WOK",
>     "to_loc":"WAT",
>     "from_time":"0700",
>     "to_time":"0800",
>     "from_date":"2018-01-22",
>     "to_date":"2018-01-23",
>     "days":"WEEKDAY"
> }'
date
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.2.15 (CentOS) Server at hsp-prod.rockshore.net Port 443</address>
</body></html>
andrew@andrew-SVF1521A1EW:~$ date
Wed 21 Mar 20:59:40 GMT 2018

If I use browser to go to https://hsp-prod.rockshore.net/api/v1/serviceMetrics, it prompt me username/password. i filled it with the email and password used in curl, it came back with 

HTTP Status 405 - Request method 'GET' not supported



I'm using bash under ubuntu by the way, not that it matters....

Chris Northwood

unread,
Mar 23, 2018, 5:15:19 AM3/23/18
to A gathering place for the Open Rail Data community
Kai,

Are you literally including the text with a curly bracket and the words base64? You should instead be replacing it with the Base64 equivalent. I don't think Curl does the conversion for you!

On Wed, Mar 21, 2018 at 9:05 PM, Kai Zhang <cmsk...@gmail.com> wrote:
there is a delay of 60s before I get the error.
With the curl command, did you need to put any space between Basic and { ? I tried both, either works. 
Also I tried to remove \ before ", same issue


$ date 
Wed 21 Mar 20:58:38 GMT 2018
andrew@andrew-SVF1521A1EW:~$ curl -X POST \
>   -H 'Authorization: Basic {Base64(\"myemail@registered.com\":\"Maya4pro+\")}' \
To unsubscribe from this group and stop receiving emails from it, send an email to openraildata-talk+unsubscribe@googlegroups.com.
To post to this group, send email to openraildata-talk@googlegroups.com.

Kai Zhang

unread,
Mar 27, 2018, 5:40:40 AM3/27/18
to A gathering place for the Open Rail Data community
Now I've removed curly bracket and words base64. Same result. 


<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>

This is driving me nuts. 





On Friday, 23 March 2018 09:15:19 UTC, Chris Northwood wrote:
Kai,

Are you literally including the text with a curly bracket and the words base64? You should instead be replacing it with the Base64 equivalent. I don't think Curl does the conversion for you!
On Wed, Mar 21, 2018 at 9:05 PM, Kai Zhang <cmsk...@gmail.com> wrote:
there is a delay of 60s before I get the error.
With the curl command, did you need to put any space between Basic and { ? I tried both, either works. 
Also I tried to remove \ before ", same issue


$ date 
Wed 21 Mar 20:58:38 GMT 2018
andrew@andrew-SVF1521A1EW:~$ curl -X POST \
>   -H 'Authorization: Basic {Base64(\"mye...@registered.com\":\"Maya4pro+\")}' \
To post to this group, send email to openrail...@googlegroups.com.

Peter Hicks

unread,
Mar 27, 2018, 5:44:37 AM3/27/18
to Kai Zhang, A gathering place for the Open Rail Data community
Hi Kai

A delay of 60 seconds indicates that the HTTP Content-Length header your client is sending might be incorrect.  Can you check this?

Also, for clarity, if your username is te...@example.com and your password is letmein123, your Base64-encoded string for the Authorization header should be 'dGVzdEBleGFtcGxlLmNvbTpsZXRtZWluMTIz'.

Can you check using https://www.base64encode.org/ that you're calculating the encoded string correctly?


Peter

Reply all
Reply to author
Forward
0 new messages