Please Help with XML / HTTP Post Request,,

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Please Help with XML / HTTP Post Request,,

Postby rainer » Tue Apr 19, 2016 10:21 am

I can´t get it to work :(
There must be an error with the XML/Body attachment.

Without the XML Body it does work - but i need to attach the XML.

Can someone please help me ?

My Code:
--------------------------------------------------------------------------------------------------------------

//Create a new post request

var xmlFle = new XML('<queue>test</queue>'); // -> Creating the XML Object

var client = plugins.http.createNewHttpClient(); // Creating new http client
var poster = client.createPostRequest('https://mws.amazonservices.de');

poster.addParameter('AWSAccessKeyId','AKIAIMWQ2C12345678')
poster.addParameter('Action','SubmitFeed')
poster.addParameter('Merchant','A2D9F123456789')
poster.addParameter('MWSAuthToken','A1PA6123456789')
poster.addParameter('SignatureVersion','2')
poster.addParameter('Timestamp',time) // using a time variable -> variable works ( used and tested with other requests)
poster.addParameter('Version','2009-01-01')
poster.addParameter('Signature',signature) // Signature is correct ( used and tested with other requests)
poster.addParameter('SignatureMethod','HmacSHA256')
poster.addParameter('FeedType','_POST_PRODUCT_DATA_')
poster.addParameter('PurgeAndReplace','false')
poster.addParameter('x-amazon-user-agent','AmazonJavascriptScratchpad/1.0 (Language=Javascript)')
poster.addParameter('Content-MD5','LwpPrQqp+k0hA6qImf+wdQ==') // Value is verfied and works
poster.addParameter('Content-Type','text/xml')

poster.setBodyContent(xmlFle.toString()) // !!! the error must be here !!!

poster.setCharset('UTF-8');


var response = poster.executeRequest()

//Get the content of the response as String.e
var pageData = response.getResponseBody();

application.output(pageData)


Thank you for your help !


Rainer Böhm
rainer
 
Posts: 11
Joined: Fri Aug 17, 2012 9:58 am

Re: Please Help with XML / HTTP Post Request,,

Postby pbakker » Tue Apr 19, 2016 11:34 am

Did you inspect what xmlFle.toString() gives you? I think that gives you the string 'test', not ''<queue>test</queue>''
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: Please Help with XML / HTTP Post Request,,

Postby sbutler » Tue Apr 19, 2016 4:18 pm

pbakker wrote:Did you inspect what xmlFle.toString() gives you? I think that gives you the string 'test', not ''<queue>test</queue>''


I think you want to use:

Code: Select all
xmlFile.toXMLString()


Also notice your not setting any headers. Would double check the API and see if it requires any standard headers. For example, things like these are normally part of the header, not the poster/body:
Code: Select all
poster.addParameter('x-amazon-user-agent','AmazonJavascriptScratchpad/1.0 (Language=Javascript)')
poster.addParameter('Content-MD5','LwpPrQqp+k0hA6qImf+wdQ==') // Value is verfied and works
poster.addParameter('Content-Type','text/xml')


You probably want:
Code: Select all
poster.addHeader('x-amazon-user-agent','AmazonJavascriptScratchpad/1.0 (Language=Javascript)')
poster.addHeader('Content-MD5','LwpPrQqp+k0hA6qImf+wdQ==') // Value is verfied and works
poster.addHeader('Content-Type','text/xml')
Scott Butler
iTech Professionals, Inc.
SAN Partner

Servoy Consulting & Development
Servoy University- Training Videos
Servoy Components- Plugins, Beans, and Web Components
Servoy Guy- Tips & Resources
ServoyForge- Open Source Components
User avatar
sbutler
Servoy Expert
 
Posts: 759
Joined: Sun Jan 08, 2006 7:15 am
Location: Cincinnati, OH


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 21 guests

cron