http plugin not working

Hi
I have been trying to get the http plugin to send a request to Kapow the text gateway for some time and am getting no response, despite the URL working directly via a browser - please can someone confirm this is the correct syntax because I am certain this has worked via servoy before

var client = plugins.http.createNewHttpClient()
	var sendCheck = client.createPostRequest('http://www.kapow.co.uk/scripts/sendsms.php?username=[account]&password=[PASSWORD]&mobile=[NUMBER]&sms=This%20is%20a%20test')
application.output(sendCheck)

[Number][account][password] are replaced with the correct information

The response so far has been :

com.servoy.extensions.plugins.http.PostRequest@1905b14f

Which appears to be correct ??

Many thanks
Gordon

In your example you only created a post request object, you didn’t execute it so no http request is made. To do the actual request you have to call the executeRequest method of the created post request object. In your example ‘sendCheck.executeRequest()’. You should probably also fill the post body, otherwise use the get request.

Hope this helps.

Perfect thanks - like an idiot I thought the createPostRequest did the sending - kinda obvious if your reading the name of it

Many thanks
Gordon

Hi Gordon,
I was using the same kind of Sms api with Servoy5.1 and this kind of code should also work

The Servoy 5.1 version

function h_em_SendSMSenvoyersmspro(sender, phoneNumber, message){
/* sender=’yourname’
phonenumber=’336xxxx’ without + sign
message max 160 caracteres
*/
var deflogin=' votreloginchezsmspro ';
var defpass=’votrepasswordchezsmspro’;
var textMessage = message;
var urlpost = 'http://www.envoyersmspro.com/api/message/send';
var sessionname='smspro';
var post=plugins.http.getPoster(urlpost,sessionname)
if (post){
	post.addParameter('login',deflogin)
	post.addParameter('password',defpass)
	post.addParameter('sendername',sender)
	post.addParameter('recipients',phoneNumber)
	post.addParameter('text',textMessage)
	post.doPost()
	var data = post.getPageData();
	//analyse du resultat du post
	var res = h_em_smsCheckresult(data);
	return res
}else{
	//TODO gérer les erreurs si pas de post
}
plugins.http.deleteHttpClient(sessionname); //au cas ou

}

The Servoy 6 version should something like that (code not tested but to show you how to accomplish that)

function h_em_SendSMSenvoyersmspro(sender, phoneNumber, message){
/* sender=’yourname’
phonenumber=’336xxxx’ without + sign
message max 160 caracteres
*/
var deflogin='votreloginchezsmspro';
var defpass='votrepasswordchezsmspro';
var textMessage = message;
var urlpost = 'http://www.envoyersmspro.com/api/message/send';
var httpcli=plugins.http.createNewHttpClient()
var post=httpcli.createPostRequest(urlpost)
if (post){
	post.addParameter('login',deflogin)
	post.addParameter('password',defpass)
	post.addParameter('sendername',sender)
	post.addParameter('recipients',phoneNumber)
	post.addParameter('text',textMessage)	
	var resp=post.executeRequest()
	/* resp being a Response object you will see in Servoy dev that you can get HTTP Status code that could help you undesrstanding what going wrong with your request*/
	var httpStatus=resp.getStatusCode()
	//use a function to parse and analyse post result
	var data = resp.getResponseBody();
	var res = h_em_smsCheckresult(data);
	return res
}else{
	//TODO manage createpostrequest errors
}
	
}

Thanks for your reply !! I have implemented your V6 version.
Cheers
Gordon

Hi, in servoy 5.2 I have a method for upload files to a web server:

var url = 'url-to-web-service-in-webserver';
var filename = 'file-to-upload';
var filepath = 'path-to-file';
var p = plugins.http.getPoster(url, 'HTTPCLIENT');
p.addParameter('enviar', 1);
p.addFile('fichero', filename, filepath);
p.doPost();//do the actual post
var result = p.getPageData();

It works fine and the file selected is uploaded

In Servoy 6 I’ve modified this code for using new methods of http plugin:

var url = 'url-to-web-service-in-webserver';
var filename = 'file-to-upload';
var filepath = 'path-to-file';
var p = plugins.http.createNewHttpClient().createPostRequest(url);
p.addParameter('enviar', '1');
p.addFile('fichero', filename, filepath.getAbsolutePath());
var result = p.executeRequest().getResponseBody();

But it doesn`t work. It works if I don’t use addFile method, web server receives ‘enviar’ post param.

Any solution?

I had was a bit too literal with my response sorry, the code has the addFile issue as you suggested which I sorted, but I used the same approach. The key thing for me was getting around the html encoding of the text in the SMS message. The following works if you replace the username/password and callback numbers with real ones

function sendText(mobile,text) {	
		
	var urlpost = 'http://www.kapow.co.uk/scripts/sendsms.php'
	var client = plugins.http.createNewHttpClient();
	var post = client.createPostRequest(urlpost);
	if(post){
		post.addParameter('username','username');
		post.addParameter('password','password');
		post.addParameter('mobile','callbacknumber');
		post.addParameter('sms','this is text');
	}
	var response = post.executeRequest()
	var httpStatus = response.getStatusCode();
	var data = response.getResponseBody();
}

Ok, but it seems that addFile doesn’t sent any file in servoy 6…

I’m trying to use “version 5.2” of the plugin, replacing http.jar and http.jar.jnlp in plugins directory, but it doesn’t work, because of dependencies, I think… :?

Case created (SVY-2168), expected to be fixed in v6.0.7.

Thanks!