LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to send the string data to URL by post method in CVI?

hi members,

 

im newby at CVI and wondering if smbdy help me out on my issue having.

 

what i wanna is to send string data to "http://example.com/examplepage.html" by post method.

NOTE: example page is just for here.

 

how to implement in CVI?

 

so far I imagined and typed the code below by DataSocket:

int main()

{c

har URL[] = "http://example.com/example.html";
HRESULT res = DS_Open (URL, DSConst_Write, DSCallback, NULL, &dsHandle);

}

 

void CVICALLBACK DSCallback (DSHandle dsHandle, int event, void *callbackData)
{
HRESULT hr = S_OK;
char message[1000];
char buffer[10000];
int slength;

switch (event)
{
case DS_EVENT_STATUSUPDATED: /* on status updated*/
hr = DS_GetLastMessage (dsHandle, message, 1000);
//SetCtrlVal (panelHandle, PANEL_STATUS, message);
//DS_GetDataValue (dsHandle, CAVT_CSTRING, &buffer, 10000, &slength, NULL);

char *value = "sending the data\r\n";
DS_SetDataValue (dsHandle, CAVT_CSTRING, value, 0, 0);

//DS_GetDataValue(dsHandle, CAVT_DOUBLE, &value, sizeof(double), NULL, NULL);

break;
}
return;
}

 

many thanks!

0 Kudos
Message 1 of 5
(4,717 Views)

it is in JavaScript... i need to in CVI..

you mean it is possible to execute JavaScript code in CVI? i guess certainly NOT!

 

0 Kudos
Message 3 of 5
(4,691 Views)

Hi mashhur,

 

Do you currently have a Data Socket implementation for this (as per the code you posted) and now want to accomplish a GET/POST using C specifically?

0 Kudos
Message 4 of 5
(4,683 Views)

well...

i have done my server (uses TCP connection) in CVI and now want to send the data to the web server.

As i have been searching cvi uses Data Socket to provide esablishing connection with the web servers.

So far i typed the code below but nothing happens, i mean once i do DS_open(), my calback function does not run.

i need to help to figure out how data socket works and how to establish connection with web servers with POST method.

 

any helps highly appreciated..

 

my code is here and it is supposed to send the data to the http://www.example.asp:

 

#include <cvidef.h>
#include <cvirte.h> /* Needed if linking in external compiler; harmless otherwise */
#include <userint.h>
#include <cviauto.h>
#include <ansi_c.h>
#include "dataskt.h"


static DSHandle dsHandle = 0;

/* This is the callback function for the DataSocket */
void CVICALLBACK DSCallback (DSHandle dsHandle, int event, void *callbackData);


int main(void)
{
if (dsHandle)
{
DS_DiscardObjHandle(dsHandle);
dsHandle = 0;
}
char URL[] = "http://www.example.asp";

HRESULT res = DS_Open (URL, DSConst_Write, DSCallback, NULL, &dsHandle);

return 0;
}

 


/* This is the callback that fires whenever the data or status is updated */
void CVICALLBACK DSCallback (DSHandle dsHandle, int event, void *callbackData)
{
HRESULT hr = S_OK;
char message[1000];
char buffer[10000];
int slength;

switch (event)
{
case DS_EVENT_STATUSUPDATED: /* on status updated*/

char *value = "BUOYiD=10&DATEv=20120809113052&LATITUDE=33.12345678&LONGITUDE=126.12345678&F3_5MSV=1234.5678&F5MSV=1234.5678&W_TEMPERATURE=123.1234&SALINITY=123.1234\r\n";
DS_SetDataValue (dsHandle, CAVT_CSTRING, value, 0, 0);


break;
}
return;
}

0 Kudos
Message 5 of 5
(4,678 Views)