I have the following response for a request using Paw
<string xmlns="http://www.chemspider.com/">46c870ad-0198-4a15-95f5-d517f106fcbc</string>
And now I want to re-use the value in a second request. For this I use a dynamic value of the parsed response body and use "string" as keypath. But this doesn't work and I assume it's because of the namespace of the XML element.
Does anyone know how to specify the keypath?
Okay, I found the solution.
string.txt
Related
I am trying to add a token to a webrequest but failing message being : Specified value has invalid HTTP Header characters.
Token is : "ZN4oXXYJQ3WIdMBKR2uENi2AtE5hAocH0P3/MIBaHZA=ksRnVWCpGFw4kWagzkUfg7RXzps="
Fails when I try to add the header like this:
req.Headers.Add("X-ApiKey: ",sToken);
Do I need to base64 encode this? Or what else am I missing?
Thank you.
No need for base64. You just do not need to add colon to the header name. This colon is what makes header name invalid. You were probably following standard notation headerName: headerValue, but WebRequest will handle that formatting for you, you just need to provide the actual name and the value. So correct code should be:
req.Headers.Add("X-ApiKey", sToken);
Is XML type response parsing on the plans for PAW anytime soon? I know we can parse JSON body and create Dynamic values from them. I would love to have that feature enabled for XML response bodies too
You can parse and create dynamic values from XML, see:
To manually add a "response parsed dynamic value":
But there is no way to display the actual XML tree in a pretty way like Paw has for JSON.
The documentation for Response Parsed Body Dynamic Value doesn't make much sense to me. I r-clicked on the JSON response element as described, in this case, userid
{"authorization":"T98J_J8QcH5lC83TOKZxaWB","userid":"T98J_J8QcH5lC83TOKZxaWB","lastLogin":"2014-12-15 15:17"}
but did not receive the menu option to Copy as Dynamic Value as stated. I got the standard text editor context menu. So, either I'm misreading the doc, or it's incorrect. Here's what I want to do: Take the dynamic value for the userid and pass it as part of the URL (not a parameter) to subsequent calls. Is this possible with Paw?
Here's how you can do it manually.
Right click on the field where you want to reuse the value. In the contextual menu, pick Response > Response Parsed Body
Pick the request you want to extract the response from. Enter the JSON key path. Make it explicitly JSON format (Automatic uses the Content-Type, which may not match in some cases).
The Copy as Dynamic Value may not work if your response is not interpreted as JSON, maybe the server is not setting a Content-Type: application/json header?
I have seen examples of the request body of an HTTP PATCH request that contains JSON.
https://www.rfc-editor.org/rfc/rfc6902
An implementation of that (from https://www.mnot.net/blog/2012/09/05/patch) could look like:
[
{"replace": "/count", "value": 5}
]
I haven't seen examples of that with XML, though. Does anyone know if people are using XML as the request data format for PATCH requests?
Thanks!
It's not too hard, you just need the XML to describe the updates you want to make. It could be something absolute or relative.
<userUpdates>
<itemsViewed relative=true>3</itemsViewed>
<lastViewed>your mum</lastViewed>
</userUpdates>
Here I assumed that by default you set values absolutely.
I'm breaking my head over this for a while now and I have no clue what I do wrong.
The scenario is as followed, I'm using swfupload to upload files with a progressbar
via a webservice. the webservice needs to return the name of the generated thumbnail.
This all goes well and though i prefer to get the returned data in json (might change it later in the swfupload js files) the default xml data is fine too.
So when an upload completes the webservice returns the following xml as expected (note I removed the namespace in webservice):
<?xml version="1.0" encoding="utf-8"?>
<string>myfile.jpg</string>
Now I want to parse this result with jquery and thought the following would do it:
var xml = response;
alert($(xml).find("string").text());
But I cannot get the string value. I've tried lots of combinations (.html(), .innerhtml(), response.find("string").text() but nothing seems to work. This is my first time trying to parse xml via jquery so maybe I'm doing something fundemantally wrong. The 'response' is populated with the xml.
I hope someone can help me with this.
Thanks for your time.
Kind regards,
Mark
I think $(xml) is looking for a dom object with a selector that matches the string value of XML, so I guess it's coming back null or empty?
The First Plugin mentioned below xmldom looks pretty good, but if your returned XML really is as simply as your example above, a bit of string parsing might be quicker, something like:
var start = xml.indexOf('<string>') + 8;
var end = xml.indexOf('</string>');
var resultstring = xml.substring(start, end);
From this answer to this question: How to query an XML string via DOM in jQuery
Quote:
There are a 2 ways to approach this.
Convert the XML string to DOM, parse it using this plugin or follow this tutorial
Convert the XML to JSON using this plugin.
jQuery cannot parse XML. If you pass a string full of XML content into the $ function it will typically try to parse it as HTML instead using standard innerHTML. If you really need to parse a string full of XML you will need browser-specific and not-globally-supported methods like new DOMParser and the XMLDOM ActiveXObject, or a plugin that wraps them.
But you almost never need to do this, since an XMLHttpRequest should return a fully-parsed XML DOM in the responseXML property. If your web service is correctly setting a Content-Type response header to tell the browser that what's coming back is XML, then the data argument to your callback function should be an XML Document object and not a string. In that case you should be able to use your example with find() and text() without problems.
If the server-side does not return an XML Content-Type header and you're unable to fix that, you can pass the option type: 'xml' in the ajax settings as an override.