Motion Control and Motor Drives

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

How to send data to a website by using http client in labview?

Highlighted

Hi guys. I have to calculate distances between ports and i have more than one thousand calculation. I dont want to do this by hand. I prepared an excel sheet. First column include the first port and second column include the second port. Then i figure out that site send information how, when i press calculate button (using wireshark program to see packages). And thinking that i can parse the url; i have constant parts (like http://ports.com/sea-route) and i have variant parts (like a=Campana&b=Barcadera). I put string constant in place of caonstant parts of the url. I put contol string to place of variants then i take all datas from the excell sheet. Then concatanes all strings to obtain a complete url. After that i want to send this url to the website by using http client protocols in labview. Also, i want to take the result to the labview from the website. Fisrt of all, i ignore taking from excel sheet and tried to set the vi only for one calculation (by giving a constant url) but i failed. I share my vi. Thanks for helping and sorry my bad english Smiley Happy

0 Kudos
Message 1 of 7
(2,845 Views)

Omnom,

 

Hello! I'd like to start off by letting you know that we're in the Motion forums, and you might have better luck in the LabVIEW forums since you don't appear to be interfacing with Motion hardware or software. In fact, I would advise just opening a new post in the LabVIEW forums and seeing if you don't get more replies. I believe I understand what you wish to do with this program. It sounds like there is a database of port locations online that you would like to grab data from and calculate distances between ports. Is this correct? If so, what is the problem you're running into? If that's not correct, please describe the behavior you would like to see and the behavior you are seeing so we can try to find a good solution.

Austin
Product Support Engineer
National Instruments
0 Kudos
Message 2 of 7
(2,807 Views)

Hello Austin,

First of all, i thank you for advice. I am new on this program as you see Smiley Happy

Let me tell you what i want. I create a web service and i redirect my web service to the web page which i want to send and take data. (I took the index.html of the web page to be able to use it as a web server.) 

this is the web page url => http://ports.com/sea-route/

and this is the data that i want to concatanate url =>  #/a=0&b=0&c=annaba&d=cabinda 

and final url => http://ports.com/sea-route/#/?a=0&b=0&c=annaba&d=cabinda

However, i have some troubles with my vi.
- I cannot reach another page (in the final url) when i enter values to the url. Is this because of locale debugging option?
-When i run the program, why it doesnt go directly to the defined url? I have to enter the url in to browser.vi.pngproject.png
0 Kudos
Message 3 of 7
(2,801 Views)

Thanks for the additional details! What behavior are you seeing when you attempt to reach the URL? Also, I don't see where you are explicitly trying to reach the ports.com URL. Is that the Key value going into the Read Session Variable VI? Also, would it be possible for you to post your VI so I could debug it and get a better idea of what's going on?

Austin
Product Support Engineer
National Instruments
0 Kudos
Message 4 of 7
(2,776 Views)

I changed something in my vi and i achieved to reach the web page, but now i can not get the result that i want. I want to reach the distance value but when i enter the web service url to the browser's url part, it returns an empty value. I share all project in a zip file. If you take a look, i appreciate.

Thank you very much...

0 Kudos
Message 5 of 7
(2,774 Views)

Thank you for the code! It sounds like you're at a point where you can access the website, but are not seeing any values being returned. To me this sounds like there may be a formatting error in your URL. 

 

I'd like to confirm my understanding of what you want to do. It sounds like you want to use this tool (ports.com) to determine the distance between two ports. You want to send data to this website via HTTP commands in LabVIEW. It sounds like you've got an Excel sheet full of port names that you want to run through so you can determine the distances between each of them.

 

If this is the case, I believe there is an easier way to do it. I'm not sure why you have created your own web page. I believe you were closer to a solution with your first attempt. What was the problem you were seeing with your original code? (The one denoted as My_VI in your first post)

 

Also please let me know if there is some aspect of your application that I don't understand.

Austin
Product Support Engineer
National Instruments
0 Kudos
Message 6 of 7
(2,750 Views)

Austin is correct that you really don't want to be setting up your own webservice. What you are looking to do is scrape their website since it sounds like they do not have a public API. You can use websockets for this. You will enter a url (that you create from your excel sheet), you will get back a html representation of the page, you then do a pattern match to determine your distance. I tested it out and it seems like websockets were not too happy with the url you were trying, http://ports.com/sea-route/#/?a=0&b=0&c=annaba&d=cabinda, but it works with the link url, http://ports.com/sea-route/port-of-annaba,algeria/port-of-cabinda,angola/ .  Here is a snippet of sample code I wrote up.  I am using regex to pull out the distance from the rest of the contents of the page.sea-port-scraper.png

0 Kudos
Message 7 of 7
(2,742 Views)