Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Progark gruppe 3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Ingebrigt Ørstad
Progark gruppe 3
Commits
26bcd2c0
Commit
26bcd2c0
authored
5 years ago
by
ivarnm
Browse files
Options
Downloads
Patches
Plain Diff
#10
Add sendRequest methods
parent
3343cb91
No related branches found
No related tags found
1 merge request
!34
Resolve "SinglePlayerSelectGameState"
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/core/src/com/gameware/game/QueryIntermediate.java
+50
-9
50 additions, 9 deletions
frontend/core/src/com/gameware/game/QueryIntermediate.java
with
50 additions
and
9 deletions
frontend/core/src/com/gameware/game/QueryIntermediate.java
+
50
−
9
View file @
26bcd2c0
...
...
@@ -5,35 +5,76 @@ import com.badlogic.gdx.Net;
import
com.badlogic.gdx.Net.HttpMethods
;
import
com.badlogic.gdx.Net.HttpRequest
;
import
com.badlogic.gdx.Net.HttpResponse
;
import
com.badlogic.gdx.net.HttpParametersUtils
;
import
java.util.Map
;
public
class
QueryIntermediate
{
private
static
String
baseUrl
=
"http://localhost:3001/api"
;
private
static
String
baseUrl
=
"http://localhost:3001/api/"
;
private
static
void
testApi
()
{
System
.
out
.
println
(
"testApi"
);
public
static
String
[]
sendGetRequest
(
String
route
)
{
HttpRequest
request
=
new
HttpRequest
(
HttpMethods
.
GET
);
request
.
setUrl
(
"http://libgdx.badlogicgames.com/nightlies/dist/AUTHORS"
);
request
.
setUrl
(
baseUrl
+
route
);
System
.
out
.
println
(
"GET: "
+
baseUrl
+
route
);
final
String
[]
response
=
new
String
[
2
];
Gdx
.
net
.
sendHttpRequest
(
request
,
new
Net
.
HttpResponseListener
()
{
@Override
public
void
handleHttpResponse
(
HttpResponse
httpResponse
)
{
System
.
out
.
println
(
"response: "
+
httpResponse
.
getResultAsString
());
response
[
0
]
=
httpResponse
.
getStatus
().
getStatusCode
()
+
""
;
response
[
1
]
=
httpResponse
.
getResultAsString
();
//System.out.println(response);
}
@Override
public
void
failed
(
Throwable
t
)
{
response
[
0
]
=
"500"
;
response
[
1
]
=
"Failed"
;
System
.
out
.
println
(
"Something went wrong"
);
}
@Override
public
void
cancelled
()
{
response
[
0
]
=
"500"
;
response
[
1
]
=
"Cancelled"
;
System
.
out
.
println
(
"Cancelled"
);
}
});
while
(
response
[
1
]
==
null
)
{
try
{
Thread
.
sleep
(
50
);
System
.
out
.
println
(
"Sleeping"
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
return
response
;
}
public
static
String
[]
sendPostRequest
(
String
route
,
Map
<
String
,
String
>
params
)
{
HttpRequest
httpPost
=
new
HttpRequest
(
HttpMethods
.
POST
);
httpPost
.
setUrl
(
baseUrl
+
route
);
httpPost
.
setHeader
(
"Content-Type"
,
"application/x-www-form-urlencoded"
);
httpPost
.
setContent
(
HttpParametersUtils
.
convertHttpParameters
(
params
));
final
String
[]
response
=
new
String
[
2
];
Gdx
.
net
.
sendHttpRequest
(
httpPost
,
new
Net
.
HttpResponseListener
()
{
public
void
handleHttpResponse
(
Net
.
HttpResponse
httpResponse
)
{
response
[
0
]
=
httpResponse
.
getStatus
().
getStatusCode
()
+
""
;
response
[
1
]
=
httpResponse
.
getResultAsString
();
//System.out.println(response);
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"hello"
);
QueryIntermediate
.
testApi
();
public
void
failed
(
Throwable
t
)
{
System
.
out
.
println
(
"failed"
);
}
public
void
cancelled
(){
System
.
out
.
println
(
"cancelled"
);
}
});
return
response
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment