I have an http api that give me html response, and I want to "preview" it.
But there is some javascript code in it, and without execute them, it won't give me the right page.
I currently manually copy & paste them in some aaa.html file and use chrome to open it(file://aaa.html), but I want to simplified those steps.
Is there anyway to do that in postman? or is there any postman alternative can do that?
There is an alternative to do this in Postman itself. You will have to use pm.visualizer. Just open your API request which is giving you the HTML response. Then go to the Test tab, add the lines below, and then click on the Visualize tab:
// save your html response in the template and then
const template = pm.response.text();
// set that template to pm.visualizer
pm.visualizer.set(template);
From Postman official documentation
Postman provides a programmable way to visually represent your request responses. Visualization code added to the Tests for a request will render in the Visualize tab for the response body, alongside the Pretty, Raw, and Preview options.
You need add to the Tests for a request:
var template = pm.response.text();
pm.visualizer.set(template);
and see result on the Visualize tab (after Pretty, Raw, and Preview options).
Postman result HTML with JS and CSS
To fix the error:
Refused to load the image 'file:///C:/some.png' because it violates the following Content Security Policy directive: "img-src http: https: data:".
if the content simply does not find (404 Not Found) it along a similar path 'file:///C:/some.file'
need to add the HTML tag to the section of the response body:
var response = pm.response.text();
var base = '<base href="https://some.domain/">";
var template = response.replace('<head>', '<head>' + base);
pm.visualizer.set(template);
this answer also solves the question in this comment.
For more information:
Postman Visualizing responses
HTML <base> tag in MDN Web Docs
Related
So I have this url in my site
localhost/home-loan
And when clicked, it performs the following function from the controller page
mortgage_loans_controller.rb
I then fill up a form and click submit. But i want my submit page to have the following url,
localhost/home-loan/thank-you
But it has localhost/mortgage_loans/thank_you
thank_you is also another function in the mortgage_loans_controller.
How can i do this?
Use this:
match '/home-loan/thank-you', to: 'your_controller#your_action', as: 'custom_name_for_helper', via: [:post]
Place this line inside of the routes.rb.
This line says that whenever you doing POST request to the localhost/home-loan/thank-you, execute your_controller's your_action.
as: options will use 'custom_name_for_helper' to create path helper, like custom_name_for_helper_path.
via: option determines which request method used, if you need to handle all types just use via: :all
I don't know the structure of your routes.rb, so place this line above all routes, to be sure that it will work.
What I am trying to achieve is to find a way of displaying a wiki page content in a floating iFrame ( and of course keep the styling ) for a tool that I am developing for our employees. Right now the tool I made is using jQuery dialog box to display a specific document / pdf, For compatibility and usability purposes I would really like to upgrade that so it uses a wiki page instead of documents / PDFs.The problem that I am facing is that there is no really direct link to the content of a Sharepoint wiki page instead the only available direct link is the one to the page all together with all the navigation menus, option panel, user panel etc. I want to avoid using javascrip to strip away these elements. Instead I am simply trying to find out if sharepoint 2013 has some more elegant way of providing the content such as: Web service or javascript SP API.
My ideas so far:
REST Url to give the content back? I know for sure it works for lists and libraries but I couldn't find anything in the REST API About wiki page content
SP.js ? Couldn't find anything about that either
Anyways, it could be possible that I have overlooked things, or probably haven't searched hard enough. However, any help is very very welcome. If you don't know about a concrete solution I would be very happy with nice suggestions too :)
If there is nothing out of the box I will have to get to my backup plan of a jQuery solution to get the page and strip off all unnecessary content and keep the styling.
I believe you are on the right track with REST API, in Enterprise Wiki Page the content is stored in PublishingPageContent property.
The following example demonstrates how to retrieve Enterprise Wiki Page content:
var getWikiPageContent = function (webUrl,itemId,result) {
var listTitle = "Pages";
var url = webUrl + "/_api/web/lists/GetByTitle('" + listTitle + "')/items(" + itemId + ")/PublishingPageContent";
$.getJSON(url,function( data ) {
result(data.value);
});
}
Usage
getWikiPageContent('https://contoso.sharepoint.com/',1,function(pageContent){
console.log(pageContent);
});
And something for those of you who like to have more than one different examples:
var inner_content;
var page_title = "home";
$.ajax({
url: "https://mysharepoint.sharepoint.com/MyEnterpriseWikiSite/_api/web/Lists/getbytitle('Pages')/items?$filter=Title eq '" + page_title +"'",
type: "GET",
headers: {
"ACCEPT": "application/json;odata=verbose"
},
success: function (data) {
if (data.d.results[0]) {
inner_content = data.d.results[0].PublishingPageContent;
}
},
error: function(){ //Show Error here }
});
That's what did the job for me.
This example fetches the inner content of an Enterprise wiki page by Title( make sure you are not using the Name of the page, although Title and Name can be given the same string value, they are different fields in sharepoint 2013 )
I have multilingual website and I want a custom 404 page in all languages which depends on the context of the site. What is the correct approach to get the 404 page defined in content tree or to access 404 page from content tree? I am able to get 404 page if I will define that in my site root but not from content tree.
I want 404page from the content tree as my 404 Custom redirect.
My Webconfig setting:
<setting name="ItemNotFoundUrl" value="/404Page.aspx" />
IIS 404 entry.
The error i got when page is not there in sitecore:
After changing IIS to default and setting httpErrors like
<error statusCode="404" path="/404PAGE.aspx" responseMode="ExecuteURL" />
</httpErrors>
I use a custom implementation of the ExecuteRequest processor in the httpBeginRequest pipeline.
That is where the 404 requests are eventually handled.
You can override the RedirectOnItemNotFound method in there and add some logic to load a different 404 page per site.
Take a look at this blog post that explains how to implement it.
EDIT: I have added an example of how to implement it so you can return a site specific 404 page.
If you make this modification, you can return a different 404 page per site:
Add this to the configuration:
<setting name="NotFoundPage.SiteName1" value="/not-found.aspx" />
<setting name="NotFoundPage.SiteName2" value="/not-found.aspx" />
Then in the custom RedirectOnItemNotFound code, do this to return site specific 404 content:
public class ExecuteRequest : Sitecore.Pipelines.HttpRequest.ExecuteRequest
{
protected override void RedirectOnItemNotFound(string url)
{
var context = System.Web.HttpContext.Current;
try
{
// Get the domain of the current request.
string domain = context.Request.Url.GetComponents(UriComponents.Scheme | UriComponents.Host, UriFormat.Unescaped);
// Get 'not found page' setting for current site.
string notFoundUrl = Sitecore.Configuration.Settings.GetSetting(string.Conact("NotFoundPage.", Sitecore.Context.Site.Name));
// Request the contents of the 'not found' page using a web request.
string content = Sitecore.Web.WebUtil.ExecuteWebPage(string.Concat(domain, notFoundUrl));
// Send the content to the client with a 404 status code
context.Response.TrySkipIisCustomErrors = true;
context.Response.StatusCode = 404;
context.Response.Write(content);
}
catch (Exception)
{
// If our plan fails for any reason, fall back to the base method
base.RedirectOnItemNotFound(url);
}
// Must be outside the try/catch, cause Response.End() throws an exception
context.Response.End();
}
}
The idea is that you use the site name as setting key so you can resolve the configuration value per site.
The code needs some work of course, but you get the idea..
EDIT 2: Added example configuration to replace the original pipeline processor with the new one:
<pipelines>
<httpRequestBegin>
<processor type="Sitecore.Pipelines.HttpRequest.ExecuteRequest, Sitecore.Kernel">
<patch:attribute name="type">ParTech.Pipelines.ExecuteRequest, ParTech</patch:attribute>
</processor>
</httpRequestBegin>
</pipelines>
Sitecore does some of its own "item not found" handling, and also doesn't do a good job of handling 404s in an SEO-friendly manner.
The best solution I've found for handling 404s and other errors in Sitecore is the Sitecore Error Manager.
http://marketplace.sitecore.net/en/Modules/Sitecore_Error_Manager.aspx
https://github.com/unic/SitecoreErrorManager/wiki
You can set ItemNotFoundUrl in Sitecore config to any item in the content tree, it does not need to be in the site root, and as long as you don't specify a language it will use whatever the user has been browsing the site in (or default for first visit). The item has to be in the same tree structure for all sites though:
<setting name="ItemNotFoundUrl" value="/errors/404.aspx" />
<setting name="LayoutNotFoundUrl" value="/errors/500.aspx"/>
<setting name="NoAccessUrl" value="/errors/403.aspx"/>
Techphoria414 is right that Sitecore out of the box does not do a good at handling 404s in an SEO friendly manner, it will do a 302 redirect to the error page. However, if you set the following to true then a Server.Transfer will be used:
<!-- USE SERVER-SIDE REDIRECT FOR REQUEST ERRORS
If true, Sitecore will use Server.Transfer instead of Response.Redirect to redirect request to service pages when an error occurs (item not , access denied etc).
Default value: false
-->
<setting name="RequestErrors.UseServerSideRedirect" value="true"/>
Which triggers the following code in the ExecuteRequest pipeline.
protected virtual void PerformRedirect(string url)
{
if (Settings.RequestErrors.UseServerSideRedirect)
HttpContext.Current.Server.Transfer(url);
else
WebUtil.Redirect(url, false);
}
You can read more about it in this blog post. Be sure to set Status property of the current System.Web.HttpResponse to 404 in your code that handles it. There is more info in the Handling HTTP 404 document.
Error Manager is a great module though and is much more flexible if you need to set different url locations for different sites.
I have written a blog post on this, might be useful for someone in future.
http://sitecoreblog.tools4geeks.com/Blog/35/Better-way-of-handling-sitecore-404-pages
The approach i have taken is :
Add a processor after HttpRequest.ItemResolver on HttpRequestBegin pipeline.
Find if context item is null, if null set 404 content page as context item.
Add another processor in the pipeline httpRequestEnd after EndDiagnostics processor to set the 404 status code for not found Item.
With this approach, we don't need to set 404 status code on Renderings. As we are setting it at the end of "httpRequestEnd" pipeline. /404 page returns 200 status code as this page suppose to return 200 status code.
works in multi-site/multi-language environment.
I originally followed this tutorial (https://django-haystack.readthedocs.org/en/latest/tutorial.html), and have so far been able to highlight my query within my returned results. However, I want to highlight this same query when visiting the next page that I load with a separate template. Is there any way to save/access this query so that I can highlight the same results within this other template?
Whenever I try and include a statement like this, I get an error, which I'm thinking is because I'm not trying to access the query properly.
{% highlight section.body with query html_tag "span" css_class "highlighted" %}
You have to send to the next page, the information that you use to highlight the results in the first page. You can use the request.session to store the data and call it in the next page, or you can send the sqs by the url to the next page.
If you want to know how to manage the search query set, and how to edit that kind of stuff, I recommend you to read the views.py forms.py and the elasticsearch_backend in the haystack folder at: "/usr/local/lib/python2.7/dist-packages/haystack"
This is the url for the documentation of Django Session: Django Session
This is the url for the documentation to pass parameters trhough url: URL dispatcher
I have a simple html page that sources a javascript file. The javascript file's only purpose is to write the following...
document.write('<img src="http://www.location.com/image.png">');
Once the information has been written, im needing some javascript to extract the url and the image source and return the url and image locations alone.
Any help is appreciated. Thank you in advance!
Check out this answer which gives shows you how to do it with JQuery or just plain Javascript
UPDATE:
If you have the ability to modify the HTML, then why don't you put in a DOM element that you can hook on to right after where the image will be inserted? Then you can use the following JQuery:
var linkDest = $('#Anchor').prev().attr('href');
var imgSrc = $('#Anchor').prev().children().attr('src');
Which you can see in this JSFiddle example