I want to make an http request to a REST API when a Smartfox Login Request is made.
The response from that API will be used to do some processing in the extension.
I could not find any way to make htto request from JAVA.
Is there any way to do it ?
Make HTTP Request from Java extensiom
Re: Make HTTP Request from Java extensiom
Hi,
SmartFoxServer 2X comes with the Apache HTTP Client library, which is a useful set of API for sending HTTP requests to a remote server.
You just need to add the jars to your project:
SFS2X/lib/httpclient-4.5.2.jar
SFS2X/lib/httpcore-4.4.4.jar
(version numbers may be different, based on the version of SFS2X)
Also you can check some examples of usage here:
https://www.vogella.com/tutorials/Apach ... ticle.html
Hope it helps
SmartFoxServer 2X comes with the Apache HTTP Client library, which is a useful set of API for sending HTTP requests to a remote server.
You just need to add the jars to your project:
SFS2X/lib/httpclient-4.5.2.jar
SFS2X/lib/httpcore-4.4.4.jar
(version numbers may be different, based on the version of SFS2X)
Also you can check some examples of usage here:
https://www.vogella.com/tutorials/Apach ... ticle.html
Hope it helps
Re: Make HTTP Request from Java extensiom
I have added these 2 libraries in lib folder but I am not sure how do I import them into my extension code.
I tried the following but it gives error
"import org.apache.http.client.HttpClient;"
I would need HttpClient ,HttpGet , HttpResponse ,HttpPost references. Can you please help how do I get these references?
The following is my code which I will be using to see if http request was successful(URL will be changed)
client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://www.vogella.com");
HttpResponse response = client.execute(request);
I tried the following but it gives error
"import org.apache.http.client.HttpClient;"
I would need HttpClient ,HttpGet , HttpResponse ,HttpPost references. Can you please help how do I get these references?
The following is my code which I will be using to see if http request was successful(URL will be changed)
client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://www.vogella.com");
HttpResponse response = client.execute(request);
Re: Make HTTP Request from Java extensiom
Just to be clear... we're talking about SFS2X, correct?
Because this was posted under SFS PRO 1.x
Thanks
Because this was posted under SFS PRO 1.x
Thanks
Re: Make HTTP Request from Java extensiom
Oops! Sorry for that.
Since I am new here I didn't check into where should I post. I saw "Server side extension development" and posted it.
Yes I am talking about SFS2X.
Since I am new here I didn't check into where should I post. I saw "Server side extension development" and posted it.
Yes I am talking about SFS2X.
Re: Make HTTP Request from Java extensiom
Ok, no problem. I've moved the post in the right section.
Did you check the examples from the article I've linked?
Should be pretty straightforward. In the while loop you can decode the response from the server.
Makes sense?
Cheers
Did you check the examples from the article I've linked?
Code: Select all
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://www.vogella.com");
HttpResponse response = client.execute(request);
// Get the response
BufferedReader rd = new BufferedReader
(new InputStreamReader(
response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
// Parse the response from the server
}
Should be pretty straightforward. In the while loop you can decode the response from the server.
Makes sense?
Cheers
Re: Make HTTP Request from Java extensiom
Yes, it is working.
Thanks
Thanks
Re: Make HTTP Request from Java extensiom
I need two ways of making a http request here.
One is I want to wait until request is made and response is recieved.
Second is I want to make an http request and not wait for response.
Is there any way for this?
One is I want to wait until request is made and response is recieved.
Second is I want to make an http request and not wait for response.
Is there any way for this?
Who is online
Users browsing this forum: No registered users and 104 guests