I have been doing some test about a HelloWorld on sencha, but anyway I can't get it to work con a responseXML. My code is something like this...
Ext.Ajax.request({
url: 'http://url/MobileService/MobileWS.asmx',
callbackKey: 'callback',
scope: 'this',
method: 'POST',
headers: {'Content-Type': 'application/soap+xml; charset=utf-8; action="http://tempuri.org/HelloWorld"'},
success: function(response) {
// OK
alert("ok");
alert(response.responseXML);
},
failure: function(response) {
// KO
alert("errpr");
alert(response.resposeText);
},
xmlData: '<?xml version="1.0" encoding="utf-8"?>\n<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns="http://tempuri.org/HelloWorld"><soap:Header/><soap:Body><HelloWorldResult>string</HelloWorldResult></soap:Body></soap:Envelope>'
});
This piece of code, is returning in responseText all the xml info I need, but is not showing up on responseXML. Furthermore I don't know how to look for the XML key and get the value.
The real problem comes across when I want to consume a bigger Service, in which I have to include some input parameters. The problem, it simply does not work. Perhaps jam doing it wrong. I'am just adding this to the other code before headers key.
params:{filter:'SomeName'}
I have been reading some sencha documentation, and I found out that there should be some way to create both model and sources to consume SOAP WebService, but I am not being able to do that. Any Help?
Found this somewhere. It's not mine:
In order for the browser to parse a returned XML document, the Content-Type header in the HTTP response must be set to "text/xml" or "application/xml". This is very important - the XmlReader will not work correctly otherwise.
Other than that you might want to go for JSON anyways.
Try this link:
http://davidwalsh.name/convert-xml-json
Related
I am trying to query an API where I have to pass username and password in the body. I have researched multiple methods but have not found any method which seems reasonable.
My query looks something like this:
URL:
localhost:8080/v1/project
HEADERS:
Content-Type: application/json
BODY:
{
"email": "test#test.com",
"password": "123456"
}
In the docs I have found WebActions.Request, which is aparently disabled in most contexts (https://learn.microsoft.com/en-us/powerquery-m/webaction-request).
Web.Contents only allows a body in POST requests (https://learn.microsoft.com/en-us/powerquery-m/web-contents).
I'd rather not write a Python script to do it as it requires a Python installation.
I tried this possible solution, but there was no success, as it would still perform a POST request: https://community.powerbi.com/t5/Power-Query/How-to-send-a-GET-method-with-content-data-with-M/m-p/943033/highlight/true#M32541
What reasonable way is there to achieve my goal to do a GET request with a body containing the credentials?
I regularly use Tabulator's setData() method. I usually set parameters in the URL args, and have no problems with it. But I now have a complex use case that will be easier to solve if I can put a JSON payload into the request.
I've followed the Tabulator documentation for an advanced configuration.
I've made a series of attempts (putting the JSON in various places, using quotes/double quotes in the JSON, etc) at trying to work out the problem. The Flask server always returns this error:
Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)
What makes me suspect the problem is with Tabulator, not Flask, is because I printed request.__dict__ and couldn't find the JSON in the request. (I.e. that seems to the reason for the error.)
The below example, which triggers the same error, is taken from the Fetch documentation (Tabulator uses the Fetch API).
Is there anything wrong with the below or should I be looking harder at Flask?
const data = { username: 'example' };
var ajaxURL = "/data/results";
var ajaxConfig = {
method:"POST",
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrf_token,
},
body: JSON.stringify(data)
};
ResultsTable.setData( ajaxURL, {}, ajaxConfig);
Notes:
I'm using the latest version of Tabulator (4.9).
ResultsTable is set elsewhere in the code and is successfully loading default data when the page loads. The use case kicks in when the user sets their own parameters for the data.
The CSRF token, which is set elsewhere in the code, is there because Flask requires it.
The reason that is failing is that Tabulator will build out its own request body when it builds a request and that will override your config.
In your usage case, you will need to override the build in ajax request promise and add your own function that makes the ajax request and then resolves the data.
You can do this using the ajaxRequestFunc.
Checkout the Ajax Request Documentation for full details
Description
Unable to match a simple Soap body with x-mock-match-request-body.
To Reproduce
Steps to reproduce the behavior:
Create an example for a mock server with any url, any http verb and any response
e.g. POST {{url}}/test with the response:
{
"test":"test"
}
Add the following request body in the example:
<soap:Envelope>
</soap:Envelope>
Create a request pointed at the example url with the same body as the example body
Send the request
Add the header x-mock-match-request-body and give the value true
Send the request
Expected behavior
Step 4 is expected to return the example response as the body is not matched and the http verb and url path is correct - this works as expected
Step 6 is expected to return the example response as the body is the same as specified in the example and the http verb and url path is correct - this does NOT work as expected
Screenshots
Mock example:
Mock example headers and response:
Request with body matching:
Headers and response:
Headers and response without body matching:
App Type [Native App]
Postman Version [7.24.0]
OS: [Windows 10 Enterprise]
I am able to match a JSON-body without issue. Has anyone experienced this when using SOAP?
I added the header Content-type: Application/xml to both the example and the request and it worked.
I'm attempting to upload raw image data to S3 in the context of a react-native app.
I have the raw data correct and for the most part I think my code inside react native is working correctly to capture image data.
On my rails server, I'm using the amazon ruby gem to build the details of the url and associated authentication data required to post data to the bucket in question which I'm then rendering into react-native just like a regular react web front end.
# inside the rails server controller
s3_data = S3_BUCKET.presigned_post(key: "uploads/#{SecureRandom.uuid}/${filename}", success_action_status: '201', acl: 'public-read', url: 'https://jd-foo.s3-us-west-2.amazonaws.com')
render json: {s3Data: {fields: s3_data.fields, url: s3_data.url}}
At the moment I attempt to post to S3, I'm using ES6 fetch like the below to build my http request.
saveImage(data) {
var url = data.url
var fields = data.fields
var headers = {'Content-Type': 'multipart/form-data'}
var body = `x-amz-algorithm=${encodeURIComponent(fields['x-amz-algorithm'])}&` +
`x-amz-credential=${encodeURIComponent(fields['x-amz-credential'])}&` +
`x-amz-date=${encodeURIComponent(fields['x-amz-date'])}&` +
`x-amz-signature=${encodeURIComponent(fields['x-amz-signature'])}&` +
`acl=${encodeURIComponent(fields['acl'])}&` +
`key=${encodeURIComponent(fields['key'])}&` +
`policy=${encodeURIComponent(fields['policy'])}&` +
`success_action_status=${encodeURIComponent(fields['success_action_status'])}&` +
`file=${encodeURIComponent('12foo')}`
console.log(body);
return fetch(url, {method: 'POST', body: body, headers: headers})
.then((res) => {console.log('s3 inside api res', res['_bodyText']) ; res.json()} );
}
the logging of the body looks like
x-amz-algorithm=AWS4-HMAC-SHA256&x-amz-credential=AKIAJJ22D4PSUNBB5RAQ%2F20151027%2Fus-west-1%2Fs3%2Faws4_request&x-amz-date=20151027T223159Z&x-amz-signature=42b09d7ae134f803b10ef72d220fe74a630a3f826c7f1f625448277d0a6d93c7&acl=public-read&key=uploads%2F46be8ca3-6d3a-4bb7-a658-f2c8e058bc28%2F%24%7Bfilename%7D&policy=eyJleHBpcmF0aW9uIjoiMjAxNS0xMC0yN1QyMzozMTo1OVoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJqZC1mb28ifSxbInN0YXJ0cy13aXRoIiwiJGtleSIsInVwbG9hZHMvNDZiZThjYTMtNmQzYS00YmI3LWE2NTgtZjJjOGUwNThiYzI4LyJdLHsic3VjY2Vzc19hY3Rpb25fc3RhdHVzIjoiMjAxIn0seyJhY2wiOiJwdWJsaWMtcmVhZCJ9LHsieC1hbXotY3JlZGVudGlhbCI6IkFLSUFKSjIyRDRQU1VOQkI1UkFRLzIwMTUxMDI3L3VzLXdlc3QtMS9zMy9hd3M0X3JlcXVlc3QifSx7IngtYW16LWFsZ29yaXRobSI6IkFXUzQtSE1BQy1TSEEyNTYifSx7IngtYW16LWRhdGUiOiIyMDE1MTAyN1QyMjMxNTlaIn1dfQ%3D%3D&success_action_status=201&file=12foo
It seems like my problems could be tied to both
Bad format of the post body including problems with special characters
Not providing S3 with enough data in post body including keys and other information, the documentation feels a bit unclear about what is/is not required.
The error back from S3 servers looks like
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>MalformedPOSTRequest</Code><Message>The body of your POST request is not well-formed multipart/form-data.</Message> <RequestId>DCE88AC349D7B2E8</RequestId><HostId>AKE1xctETuZMAhBFLfyuFlDxikYUlbAC7YufkM7h8Z8eVQdtLA25Z0Od/a4cMUbfW1nWnGjc+vM=</HostId></Error>
I'm pretty unclear on what my actual problems are and where I should be digging in.
Any input would be greatly appreciated.
<Message>The body of your POST request is not well-formed multipart/form-data.</Message>
It may not be that you're missing values from the body. The most significant issue here is that the structure of your body does not resemble multipart/form-data.
See RFC 2388 for how multipart/form-data works. (Or find a library that builds this for you.)
What you are sending looks more like the application/x-www-form-urlencoded format, which is used by some AWS APIs, but not S3.
There is an example in the S3 docs showing what an example POST body might look like. You should see a substantial difference there.
Note also that POST is intended for browser based uploads. If you are uoloading from code, you're doing a lot of extra work. PUT Object is much more straightforward. The request body is the binary file contents. Or, if this will eventually be done by a browser, then test it with a browser, and let the browser build your form.
I'm attempting to use an ASMX web service from javascript using jQuery. It works fine when I ask for XML, but I want to make use of .net's JSON serialization functionality; (it's also starting to bug me that this isn't working)
The code for the web service:
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
[WebService()]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class SimpleService : WebService
{
[WebMethod]
public String GetString()
{
return "value";
}
}
The code for the client:
$.ajax({
type: "POST",
url: "SimpleService.asmx/GetString",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json"
});
And the response...
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
<?xml version="1.0" encoding="utf-8"?><string xmlns="http://tempuri.org/">value</string>
The request always succeeds, but jQuery gives me a parser error (not surprisingly, given the response).
I'm at my wits end. I've tried adding a ServiceMethod attribute with the ResponseType set to JSON, but nothing seems to work.
I don't want to use the .NET ScriptManager javascript generator either, so please do not suggest using them.
No answer on SO helped me solve this issue. Instead I found 2 articles describing this problem.
jQuery does not encode the request data into JSON but into a query string. This causes ASP.NET to ignore the Accept header and respond with XML.
Check this article at the title "JSON, objects, and strings: oh my!".
Here I quote:
$.ajax({
type: "POST",
url: "WebService.asmx/WebMethodName",
data: {'fname':'dave', 'lname':'ward'},
contentType: "application/json; charset=utf-8",
dataType: "json"
});
Because that data parameter is a valid object literal, calling the web service this way won’t throw any JavaScript errors on the client-side. Unfortunately, it won’t have the desired result either.
fname=dave&lname=ward
This is clearly not what we want to happen. The solution is to make sure that you’re passing jQuery a string for the data parameter, like this:
$.ajax({
type: "POST",
url: "WebService.asmx/WebMethodName",
data: "{'fname':'dave', 'lname':'ward'}",
contentType: "application/json; charset=utf-8",
dataType: "json"
});
It’s a small change in syntax, but makes all the difference. Now, jQuery will leave our JSON object alone and pass the entire string to ASP.NET for parsing on the server side.
In my case the data parameter is a big object so I use something like that to serialize it to JSON manualy.
data: JSON.stringify({'fname':'dave', 'lname':'ward'}),
Getting ASP.NET ScriptService to return JSON when querying from jQuery is very tricky and many parameters in your code can make it throw XML instead of JSON. You should read various SO Q/A to get yourself satisfied.
Related article form the same author that may give more guidance.
This one is user error.
I just stumbled upon this other stackoverflow question: web-service returning xml instead of json in net 4-0
A similar solution turned out to be what I needed. The web.config file had an httpHandler mapping for the ScriptHandlerFactory for IIS6, and I was using IIS7. Adding the httpHandler mapping to the IIS7 section of the web.config solved the problem.
I hate hidden moving parts....
Try adding the [ScriptMethod] attribute to the method:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public String GetString()