cancel
Showing results for 
Search instead for 
Did you mean: 

POST XML QUERY to SQL database through HTTP

Former Member
0 Kudos

Hi,

I having some technical issues while trying to post a SQL query to an MS SQL database through HTTP.

when I pass the query it self or the XML formated query in the URL it works fine. but as there as some size limitation I would like to post my query.

but the SQL ISAPI doesn't find it .

here is the error I'm getting back from the web server.

<H3>ERROR: 400.100 Bad Request</H3>

<b>HResult:</b> 0x80004005<br><b>Source:</b> Microsoft SQL isapi extension<br>

<b>Description:</b> Query not specified<br>

here is the XML i'm trying to send :

<ROOT xmlns:sql='urn:schemas-microsoft-com:xml-sql' > <sql:query> SELECT * FROM OF_PROJ FOR XML RAW </sql:query> </ROOT>

it works this way :

http://web server/directory?template=<ROOT xmlns:sql='urn:schemas-microsoft-com:xml-sql' > <sql:query> SELECT * FROM OF_PROJ FOR XML RAW </sql:query> </ROOT>

the problem is the size limitation.

so I'm trying to post the XML. I activated the POST in the SQL database.

here is part of the coding :

"

data : xmlbody type string,

XMLSTRING type string,

rlength type i.

concatenate

'<ROOT xmlns:sql=''urn:schemas-microsoft-com:xml-sql'' > '

'<sql:query> '

'SELECT * '

'FROM OF_PROJ '

'FOR XML RAW'

'</sql:query>'

'</ROOT> '

into xmlbody separated by space.

cl_http_client=>create_by_url( EXPORTING url = 'http://web server/dir"

IMPORTING client = http_client ).

rlength = strlen( xmlbody ).

CALL METHOD HTTP_CLIENT->REQUEST->SET_HEADER_FIELD

EXPORTING

NAME = 'Content-Type'

VALUE = 'text/xml; charset=utf-8 '.

CALL METHOD HTTP_CLIENT->REQUEST->SET_HEADER_FIELD

EXPORTING

NAME = '~request_method'

VALUE = 'POST'.

CALL METHOD HTTP_CLIENT->REQUEST->SET_CDATA

EXPORTING

DATA = xmlbody

OFFSET = 0

LENGTH = RLENGTH.

HTTP_CLIENT->SEND( ).

HTTP_CLIENT->RECEIVE( ).

HTTP_CLIENT->RESPONSE->GET_STATUS( IMPORTING CODE = RLENGTH ).

XMLSTRING = HTTP_CLIENT->RESPONSE->GET_CDATA( ).

HTTP_CLIENT->CLOSE( ).

write 😕 xmlbody.

write 😕 xmlstring.

"

any help would be appreciated.

regards,

Abdellatif

Accepted Solutions (1)

Accepted Solutions (1)

athavanraja
Active Contributor
0 Kudos

Welcome to SDN

replace the following code

CALL METHOD HTTP_CLIENT->REQUEST->SET_CDATA

EXPORTING

DATA = xmlbody

OFFSET = 0

LENGTH = RLENGTH.

with

call method HTTP_CLIENT->request->set_form_field

exporting

name = 'template'

value = xmlbody .

Regards

Raja

Former Member
0 Kudos

Hi Raja,

thanks very much. it works.

Abdellatif

Answers (0)