rest service

The 1C:Enterprise developers forum

#1
People who like this:0Yes/0No
Just came
Rating: 1
Joined: May 8, 2018
Company: Profsis Yazılım Ltd. Şti.

Hello there
I want to contact a rest service from program 1c.
Is there an example in the program 1c for this?
I want to contact http://webservice.tsoft.com.tr
http://webservice.tsoft.com.tr/rest1/console

Edited: harun Fişekci - Oct 26, 2019 10:46 AM
 
#2
People who like this:0Yes/0No
Administrator
Rating: 9
Joined: Oct 3, 2019
Company:

Hello Harun Fişekci!

Of course, you can work with REST services - the 1C platform is perfect for this!

You may to use the HTTPConnection object. For example, it may look like a code to access your service:



Code
Token = "YourToken";

ServerName = "webservice.tsoft.com.tr";
URL = "/rest1/brand/getBrands";
   
Headers = New Map;
   
Headers.Insert("token", Token);
Headers.Insert("Content-Type", "application/x-www-form-urlencoded");
Headers.Insert("FetchShowcase", True);
      
HttpQuery = New HTTPRequest(URL, Headers);
  
HttpConnection = New HTTPConnection(ServerName, 443,,,,, New OpenSSLSecureConnection);
   
HttpAnswer = HttpConnection.Post(HttpQuery, "");
   
If HttpAnswer.StatusCode = 200 Then 
      
    BodyAnswer = HttpAnswer.GetBodyAsString(TextEncoding.UTF8);
      
EndIf;




Unfortunately, I don`t have a token, so I get this answer: "Token bulunamad".


If you have any questions, I`ll be glad to answer them.

 
#3
People who like this:0Yes/0No
Just came
Rating: 1
Joined: May 8, 2018
Company: Profsis Yazılım Ltd. Şti.

Token = "bbd4c27f2fdd97710836c6c07a8d1da2";

ServerName = "http://www.atef.com.tr/rest1/console";
URL = "user/getUsers";

Headers = New Map;

Headers.Insert("token", Token);
Headers.Insert("Content-Type", "application/x-www-form-urlencoded");
Headers.Insert("FetchShowcase", True);



Couldn't resolve host name

Edited: harun Fişekci - Jan 24, 2020 01:15 PM
 
#4
People who like this:0Yes/0No
Just came
Rating: 1
Joined: May 8, 2018
Company: Profsis Yazılım Ltd. Şti.

the company we work with has given examples as follows

<ht ml>
<body>

<fo rm method="post" action="http://www.atef.com.tr/rest1/user/getUsers">
<input name="token" value="bbd4c27f2fdd97710836c6c07a8d1da2"/>
<input name="limit" value=""/>
<input name="start" value=""/>
<input name="columns" value=""/>
<input name="f" value=""/>
<input name="orderby" value=""/>
<input type="submit">
</form>

</body>
</html>

 
#5
People who like this:0Yes/0No
Just came
Rating: 1
Joined: May 8, 2018
Company: Profsis Yazılım Ltd. Şti.

I am sending you sample for a coin to sample

E-commerce site:
Visitor Address: http://webservice.tsoft.com.tr
Administration Panel: http://webservice.tsoft.com.tr/Y
Username: admin@tsoft.com.tr
Password: 12345678



Web Service Application Interface (Api Console):
Access Address: http://webservice.tsoft.com.tr/rest1/console
Username: service
Password: serv1234

 
#6
People who like this:0Yes/0No
Administrator
Rating: 9
Joined: Oct 3, 2019
Company:

Hi Harun Fişekci!

I`ll see it and write the result.

 
#7
People who like this:1Yes/0No
Administrator
Rating: 9
Joined: Oct 3, 2019
Company:

Hi Harun Fişekci!

Please send me a new token.

Just send to my mail only:  abir@1c.com

 
#8
People who like this:0Yes/0No
Just came
Rating: 1
Joined: May 8, 2018
Company: Profsis Yazılım Ltd. Şti.

harun@profsis.com

 
#9
People who like this:0Yes/0No
Administrator
Rating: 9
Joined: Oct 3, 2019
Company:

Hi Harun!

I understood the reason for the failure.

This code will work with your service:

Code
Procedure Command1(Command)
   
   Token = "YourToken";
   
   stringToken = "token=" + Token;

   ServerName = "www.atef.com.tr";
   URL = "/rest1/brand/getBrands";
      
   Headers = New Map;
      
   // Headers.Insert("token", Token); We remove this line ...
   
   Headers.Insert("Content-Type", "application/x-www-form-urlencoded");
   Headers.Insert("FetchShowcase", True);
         
   HttpQuery = New HTTPRequest(URL, Headers);
   
   
   HttpQuery.SetBodyFromString(stringToken); // ... and add this line
     
   
   HttpConnection = New HTTPConnection(ServerName, 443,,,,, New OpenSSLSecureConnection);
      
   HttpAnswer = HttpConnection.Post(HttpQuery, "");
      
   BodyAnswer = "";
   
   If HttpAnswer.StatusCode = 200 Then 
       BodyAnswer = HttpAnswer.GetBodyAsString(TextEncoding.UTF8);
   EndIf;
   
   Message(BodyAnswer);
   
EndProcedure


After these changes everything works

 
#10
People who like this:0Yes/0No
Administrator
Rating: 9
Joined: Oct 3, 2019
Company:

By the way, there is another way to work with HTTP:


Code
&AtClient
Procedure Command1(Command)
   
   WinHttp = New COMObject("WinHttp.WinHttpRequest.5.1");
   
   WinHttp.Open("POST", "https://www.atef.com.tr/rest1/brand/getBrands", False);
   
   WinHttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
   
   WinHttp.Send("token=YourToken");
   
   If WinHttp.Status = 200 Then
      Message(WinHttp.ResponseText);
   Else 
      Message("HTTP " + WinHttp.Status + " " + WinHttp.StatusText);
      Return;
   EndIf;      
   
EndProcedure



But this method works in Windows only.

 
Subscribe
Users browsing this topic (guests: 0, registered: 1, hidden: 0)
Be the first to know tips & trick on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.