LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending XML data to server with method POST

   Dear Sir/Madam,
 
I need to send XML-encoded data to a server, using the method POST. I know how to encode the data into XML, but I do not know how to send it. Which VIs do I need to use, and how do I do it?
 
Thanks!
 
Regards
Albert
0 Kudos
Message 1 of 11
(10,457 Views)
Use a TCP Open Connection, and a TCP Write, and TCP Close. Use a TCP Read
after the Write if you expect data to be send back to you. See LabVIEW's
TCP/IP examples.

See for instance http://developers.sun.com/mobility/midp/ttips/HTTPPost/ for
POST header examples. Or http://www.w3.org/Protocols/ if you want to know it
all 😉 Note that the length is critical! A wrong length will not work.
Simply wire the POST header and the data to the TCP Write, and it should
work.

Regards,

Wiebe.


0 Kudos
Message 2 of 11
(10,440 Views)

   Dear Wiebe,

Thank you for the useful links. By any chance, do you have any examples of implementation of GET or POST in LabView? I would be very grateful.

I have otherwise considered to get binded by Windows and use the embedding of Internet Explorer, which would do the work for me. The part I do not like is that it is Windows-only solution and is not transferrable to other operating systems.

Kind regards

Albert

PS

  Any body from National Instruments - here is an enhancment request: to add a function to read web pages, which would have an argument for POST data (otherwise the GET data can be easily formed by adding a text string to the site address). Matlab has such a function (actually, it has two, one for reading, urlread and one for writing, urlwrite, I think).

0 Kudos
Message 3 of 11
(10,428 Views)
If you just want to get HTML content, check out http://www.mooregoodideas.com/WinInet/index.html
 
The "WinInet Easy Get URL.vi" does what you want.
 
If you want to do it yourself, check out the attached example. Note that it was my first try too. It's not for HTML, but for wsdl. HTML should be easier though.
 
The "immediate" option isn't working for long replies. You should really parse the length, and read untill the length is reached. You could also tell the server to disconnect and read on the host untill you get an error (connection closed by peer, or something like that). Also note that some servers send some content back in packages, and I didn't find any documentation on how that works exactly. HTML content might be fine though.
 
Regards,
 
Wiebe.
Message 4 of 11
(10,418 Views)

   Hi Wiebe,

Thank you for the link and the code. The like uses Windows API, so I will try to play around with your code instead. I will probably need to look at the HTML related stadards to see what to expect (in regards to what you said about the difference in replies).

Best regards

Albert

0 Kudos
Message 5 of 11
(10,406 Views)

   Dear NI technical support,

Is this feature (POSTing the data to a server) included in the NI Internet Toolkit?

Thanks!

Regards

Albert

0 Kudos
Message 6 of 11
(10,323 Views)

Hi Albert,

I don’t think you will find the Internet Toolkit very helpful in this application. I thought that the above posts would be a very good approach.

 

Charlie M. CLD
0 Kudos
Message 7 of 11
(10,301 Views)

Hi weibe,

Thank you for the code.It is very helpful to me.About the VI(WDSL First Contact HTTP POST.vi) , can you help me to explain the document header,

POST /ip2geo/ip2geo.asmx HTTP/1.1
Host: ws.cdyne.com
Content-Type: text/xml; charset=utf-8
Content-Length: 391
SOAPAction: "http://ws.cdyne.com/ResolveIP"

 

Beacause I want to sent the data to my own web sever.So I must have some modification on it.

 

Regards,

 

水彖

0 Kudos
Message 8 of 11
(9,775 Views)

"4V" <x@no.email> wrote in message
news:1224492007449-794719@exchange.ni.com...
> POST /ip2geo/ip2geo.asmx HTTP/1.1
> Host: ws.cdyne.com
> Content-Type: text/xml; charset=utf-8
> Content-Length: 391
> SOAPAction: &quot;<a href="http://ws.cdyne.com/ResolveIP"
target="_blank">http://ws.cdyne.com/ResolveIP</a>

I'm not an expert, but I'm sure you need to modify it!

POST is the WDSL service address.
Host is the site where it's located.
Content-Type should probably always be like this for WDSL.
Content-Lenght is the lenght of the content.
SOAPAction is the name of the "function" you want to invoke.

You need to change the first two. I don't know what exactly they should be
for you. I copy-pasted the example string from cdyne's example. I'd just
fiddle around with the information given, untill I get some results.

Regards,

Wiebe.



0 Kudos
Message 9 of 11
(9,769 Views)

Dear Weibe,

 

Thank you for the code.It is very helpful to me.

Your code (WDSL First Contact HTTP POST.vi)can successfully send xml files which contain only english characters. But when the xml files contain chinese characters, the code fails to send them. Are there any methods can solve this problem?

P.S.  A chinese character occupies 3 bytes in the UTF-8 format,while  an english character occupies 1 byte

 

Regards,

icecoffee,

0 Kudos
Message 10 of 11
(9,643 Views)