1
votes

I am new to worklight and using http adapter for posting xml to webservices so that i can get the result.But I am not able to do that it is giving some error. My code is in adapter.js

function getStories(interest) {
    path = getPath(interest);

    var input = {
        method : 'post',
        returnedContentType : 'xml',
        path : path
        parameters : '<HOME><REQUEST><USERID>701692</USERID><SECURE_KEY>B6F86B1B11E9EAFC</SECURE_KEY><EMPLOYEE_ID>000000000000035B</REQUEST></HOME>'
    };


    return WL.Server.invokeHttp(input);
}

It is giving output like this

{ "errors": [ "Premature end of file.", "Failed to parse the payload from backend (procedure: HttpRequest)" ], "info": [ ], "isSuccessful": false,
"responseHeaders": { "Cache-Control": "private", "Content-Length": "0", "Date": "Mon, 15 Oct 2012 10:29:01 GMT", "Server": "Microsoft-IIS/6.0", "X-AspNet-Version": "2.0.50727", "X-Powered-By": "ASP.NET" }, "statusCode": 200, "statusReason": "OK", "warnings": [ ] }

I want to have this code (given below ) to be implemented in worklight , how can i do that.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<form name="f1" id="fi" action="http://mydoman.aspx" method="post">
<input TYPE="hidden" name="xml" value="<HOME><REQUEST><USERID>701692</USERID><SECURE_KEY>B6F86B1B11E9EAFC17F5844EE9B16669</SECURE_KEY></REQUEST></HOME>"/>

<input type="submit" value="submit"/>


</form>
</BODY>
</HTML>
3

3 Answers

1
votes

You are missing a step, you are trying to send an XML to your backend. Please read Module 5.3 - Using HTTP Adapters with SOAP Services at: https://www.ibm.com/developerworks/mobile/worklight/getting-started/index.html

The answer to your question is:

var request = <HOME><REQUEST><USERID>701692</USERID><SECURE_KEY>B6F86B1B11E9EAFC</SECURE_KEY><EMPLOYEE_ID>000000000000035B</EMPLOYEE_ID></REQUEST></HOME>;

function getStories(interest) {
    var input = {
        method : 'post',
        returnedContentType : 'xml',
        path : '',
        body : {
            content: request.toString(),
            contentType: 'text/xml; charset=utf-8'
        }
    };
    return WL.Server.invokeHttp(input);
}
0
votes

returnedContentType : 'xml' means that Worklight will try to parse the response it got from backend. Looking at the error message I can see "Content-Length": "0", which means that response body is empty, therefore it cannot be parsed to XML. Try changing returnedContentType to 'plain'.

0
votes
var request = '<HOME><REQUEST><USERID>701692</USERID><SECURE_KEY>B6F86B1B11E9EAFC</SECURE_KEY><EMPLOYEE_ID>000000000000035B</EMPLOYEE_ID></REQUEST></HOME>';

function getStories(interest) {
    var input = {
        method : 'post',
        returnedContentType : 'xml',
        path : '',
        body : {
            content: request,
            contentType: 'text/xml; charset=utf-8'
        }
    };
    return WL.Server.invokeHttp(input);
}