# http plugin not working

**URL:** <https://forum.servoy.com/t/http-plugin-not-working/15882>\
**Category:** Classic Servoy\
**Created:** [May 1, 2012, 12:55pm UTC](https://forum.servoy.com/t/http-plugin-not-working/15882 "2012-05-01T12:55:15Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gordon](https://avatars.discourse-cdn.com/v4/letter/g/3da27b/32.png) [@Gordon](https://forum.servoy.com/u/Gordon)\
**Post date:** [May 1, 2012, 12:55pm UTC](https://forum.servoy.com/t/http-plugin-not-working/15882/1 "2012-05-01T12:55:15Z")

</div>

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

```auto
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

---

<div class="post-metadata">

**Author:** ![boonstrj](https://avatars.discourse-cdn.com/v4/letter/b/9d8465/32.png) [@boonstrj](https://forum.servoy.com/u/boonstrj)\
**Post date:** [May 1, 2012, 2:15pm UTC](https://forum.servoy.com/t/http-plugin-not-working/15882/2 "2012-05-01T14:15:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Gordon](https://avatars.discourse-cdn.com/v4/letter/g/3da27b/32.png) [@Gordon](https://forum.servoy.com/u/Gordon)\
**Post date:** [May 1, 2012, 2:19pm UTC](https://forum.servoy.com/t/http-plugin-not-working/15882/3 "2012-05-01T14:19:52Z")

</div>

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

Many thanks  
Gordon

---

<div class="post-metadata">

**Author:** ![erdione](https://avatars.discourse-cdn.com/v4/letter/e/e9a140/32.png) [@erdione](https://forum.servoy.com/u/erdione)\
**Post date:** [May 1, 2012, 2:36pm UTC](https://forum.servoy.com/t/http-plugin-not-working/15882/4 "2012-05-01T14:36:43Z")

</div>

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

```auto
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)

```auto
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
}
	
}

```

---

<div class="post-metadata">

**Author:** ![Gordon](https://avatars.discourse-cdn.com/v4/letter/g/3da27b/32.png) [@Gordon](https://forum.servoy.com/u/Gordon)\
**Post date:** [May 2, 2012, 9:12am UTC](https://forum.servoy.com/t/http-plugin-not-working/15882/5 "2012-05-02T09:12:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![juan.cristobo](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@juan.cristobo](https://forum.servoy.com/u/juan.cristobo)\
**Post date:** [May 4, 2012, 12:00pm UTC](https://forum.servoy.com/t/http-plugin-not-working/15882/6 "2012-05-04T12:00:32Z")

</div>

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

```auto
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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![Gordon](https://avatars.discourse-cdn.com/v4/letter/g/3da27b/32.png) [@Gordon](https://forum.servoy.com/u/Gordon)\
**Post date:** [May 4, 2012, 1:03pm UTC](https://forum.servoy.com/t/http-plugin-not-working/15882/7 "2012-05-04T13:03:36Z")

</div>

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

```auto
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();
}

```

---

<div class="post-metadata">

**Author:** ![juan.cristobo](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@juan.cristobo](https://forum.servoy.com/u/juan.cristobo)\
**Post date:** [May 4, 2012, 1:53pm UTC](https://forum.servoy.com/t/http-plugin-not-working/15882/8 "2012-05-04T13:53:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![juan.cristobo](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@juan.cristobo](https://forum.servoy.com/u/juan.cristobo)\
**Post date:** [May 7, 2012, 8:49am UTC](https://forum.servoy.com/t/http-plugin-not-working/15882/9 "2012-05-07T08:49:42Z")

</div>

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… ![:?]( "Confused")

---

<div class="post-metadata">

**Author:** ![juan.cristobo](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@juan.cristobo](https://forum.servoy.com/u/juan.cristobo)\
**Post date:** [May 9, 2012, 1:05pm UTC](https://forum.servoy.com/t/http-plugin-not-working/15882/10 "2012-05-09T13:05:14Z")

</div>

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

Thanks!
