· 9 years ago · Sep 04, 2016, 07:42 AM
1C:UsersHAP>curl -X POST -vu android-bookmarks:123456 http://localhost:8080/oau
2th/token -H "Accept: application/json" -d "password=password&username=jlong&gran
3t_type=password&scope=write&client_secret=123456&client_id=android-bookmarks"
4* Trying 127.0.0.1...
5* Connected to localhost (127.0.0.1) port 8080 (#0)
6* Server auth using Basic with user 'android-bookmarks'
7> POST /oauth/token HTTP/1.1
8> Authorization: Basic YW5kcm9pZC1ib29rbWFya3M6MTIzNDU2
9> User-Agent: curl/7.40.0
10> Host: localhost:8080
11> Accept: application/json
12> Content-Length: 113
13> Content-Type: application/x-www-form-urlencoded
14>
15* upload completely sent off: 113 out of 113 bytes
16< HTTP/1.1 200 OK
17< Server: Apache-Coyote/1.1
18< X-Content-Type-Options: nosniff
19< X-XSS-Protection: 1; mode=block
20< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
21< Pragma: no-cache
22< Expires: 0
23< X-Frame-Options: DENY
24< Access-Control-Allow-Origin: *
25< Access-Control-Allow-Methods: POST,GET,OPTIONS,DELETE
26< Access-Control-Max-Age: 3600
27< Access-Control-Allow-Credentials: true
28< Access-Control-Allow-Headers: Origin,Accept,X-Requested-With,Content-Type,Acce
29ss-Control-Request-Method,Access-Control-Request-Headers,Authorization
30< Cache-Control: no-store
31< Pragma: no-cache
32< Content-Type: application/json;charset=UTF-8
33< Transfer-Encoding: chunked
34< Date: Sun, 04 Sep 2016 07:26:25 GMT
35<
36{"access_token":"8ac3b71e-9196-4f01-b128-4fe2cf99a1c6","token_type":"bearer","re
37fresh_token":"77a8657a-02fb-4e4a-a8bc-b2af5550540d","expires_in":40556,"scope":"
38write"}* Connection #0 to host localhost left intact
39
40curl -v http://localhost:8080/bookmarks -H "Authorization: Bearer 3f403c67-2edf-4f47-905a-6abbb530cc75"
41
42{
43 "_embedded":{
44 "bookmarkResourceList":[
45 {
46 "bookmark":{
47 "id":15,
48 "uri":"http://bookmark.com/1/jlong",
49 "description":"A description"
50 },
51 "_links":{
52 "bookmark-uri":{
53 "href":"http://bookmark.com/1/jlong"
54 },
55 "bookmarks":{
56 "href":"http://localhost:8080/bookmarks"
57 },
58 "self":{
59 "href":"http://localhost:8080/bookmarks/15"
60 }
61 }
62 },
63 {
64 "bookmark":{
65 "id":16,
66 "uri":"http://bookmark.com/2/jlong",
67 "description":"A description"
68 },
69 "_links":{
70 "bookmark-uri":{
71 "href":"http://bookmark.com/2/jlong"
72 },
73 "bookmarks":{
74 "href":"http://localhost:8080/bookmarks"
75 },
76 "self":{
77 "href":"http://localhost:8080/bookmarks/16"
78 }
79 }
80 }
81 ]
82 }
83}
84
85XMLHttpRequest cannot load http://localhost:8080/bookmarks.
86Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
87Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 401.
88XHR failed loading: GET "http://localhost:8080/bookmarks".
89
90 $.ajax({
91 url: 'http://localhost:8080/bookmarks',
92 beforeSend: function (xhr) {
93 xhr.setRequestHeader('Authorization', 'BEARER 3f403c67-2edf-4f47-905a-6abbb530cc75');
94 },
95 success: function (response) {
96 console.log(response);
97 }
98});