IM writing some html which provides a preview function for a list of URLs. I want to use an iframe for this functionality,
The issue arises when some of the URLs are broken (returning a 500 error) or when a page contains some authenication process which the requesting user cannot satisfy. In these situations the iframe is trying to display the URL but the content returned in the frame is useless (500 error or authenication error ) to the user.
DOes iframe have any built in error handling for these senarios or is there some other way i can display a generic error page if something happens when loading the iframe?
Thanks
AFAIK, there is no way to directly access the header of a response to a request initiated by an iframe (or indeed, any request) in client side script.
This is slightly convoluted, but I think it would work:
The iframe is initially loaded with a URL that refers to a script on your server, and your pass the actual URL as a GET parameter.
The server side script takes that URL, and sends a HEAD request to it (following 3xx redirects).
If the response code for the HEAD request is >= 200 and < 300, send some script back to the client which changes the iframe's src to the actual URL (you might be able to do something as simple as window.location.href = but I'm not sure without testing).
If the response code is >= 400, send a page that says "This page is not loading at the moment".
If you know PHP/have it available on your server, I can try and provide a code example.
Related
I'm a bit confused or maybe I don't fully understand http requests.
There is a website on which the search results are fetched through a GET request. I can see the whole parameter list in Firebug and if I click "search" the results are displayed as you would expect. What I don't understand is if I take this request URL (with the same parameters) and copy it in a new browser tab it doesn't return results anymore. Instead I see a 500 - Internal server error.
Can someone explain why is this happening or what can I do to see the results when accessing the URL?
As robert_b_clark suggested the solution is to send the referrer header when making the request.
I'm a noob when it comes to ASP.NET. I know few basic commands such as Response.Redirect("URL") to redirect my application web page to a different location.
However i receive HTTP Error 400 - Bad Request, whenever i try to use the code shown below
Response.Redirect(Server.UrlEncode(this.Downloadlink));
where this.Downloadlink is a user defined property which returns something like this
http://mdn.vatsag.net/fp;files/DOWNLOAD/VTSetup.exe
If i post this link in the browser, the .exe file pops up (means the link is good)
However this error comes when i use the ASP.NET code.
Any form of response on this issue/reason is deeply appreciated.
See here: http://www.kirit.com/Response.Redirect%20and%20encoded%20URIs
In short: if you quickly want to fix the issue, remove the part of your code that is UrlEncoding the URL!
For example, day, in a somewhat REST-oriented environment, a request comes in for an object that doesn't exist, like:
GET http://example.com/thing/5
Is there anything wrong with sending back a 404 response who's body is the same as a a different page? For example, responding like:
404 body: [content from "http://example.com/thing/" which is a list of things]
Does it make any sense to do this? Will this cause any problems with certain browsers? Is it confusing to the user? Or is this perfectly fine to do?
Along these same lines, I would have the content of the 404 response match the request's accept headers as best I could. (ie. abide by content negotiation with the user agent)
For example, a xml or json request would get something along the lines of a simple error message and something that says "look here for similar things", while an html request would get an HTML page that has the error message as well as the content of the list page (as I indicated above)
I think it depends on how the Restful web services are being consumed. If I'm programmatically consuming the web service from a different application, then I would want the status code together and a plain text message instead of a message decorated with HTML tags. I mean, say for example, it doesn't make sense to return a bloated 404 content if your user makes the web service call using Curl because the message will not be readable to them.
You could have different "consumes" for each restful webservice. If it's an XML request, then you return 404 and a plain text message. Otherwise, you return the error page content.
I don't see anything wrong with it. In our webservice we always send back a json error object which includes stacktraces and other details about the response. Even on a regular web server, you get at least text which can be displayed in a browser saying that you got a 404 response.
I am trying to simulate a form submission on an ASPX.NET site.
The flow of the website when accessed in a browser is as follows:
1) In a browser the user visits http://mysite.com/ which is configured with Basic Authentication
2) Upon correct credentials, the user is shown a form with one input text box and a button (URL stays http://mysite.com/ but the form being served is Default.aspx)
3)User enters some text and presses submit...
4) The page reloads... URL is still http://mysite.com/... but there is a timer which triggers after 10 secs and downloads a file from http://mysite.com/Downloader
I am trying to simulate this flow in my program using HTTPClient.
1) Do a GET on http://mysite.com
2) Extract hidden form fields __EVENTVALIDATION and __VIEWSTATE
3) Create a POST request with above two and other form fields and POST it to http://mysite.com RESULTS in Invalid Viewstate exception.
How do I achieve this in HTTPClient?
The usual way to do this is as follows: First, record the HTTP traffic using WireShark or Fiddler while you are using the website from the browser. Second, analyze the packet trace in detail, and collect every HTTP header and every HTTP payload from every GET and POST message sent by the browser. Third, try to send the same messages from your code. After sending an HTTP request, you will have to analyze the response of the server, and extract all pieces of data you need to insert into the next request. Don't forget to set the referer field, for example. Add each request to your code one by one, and record the traffic when you run the code. If you assemble your HTTP requests correctly, then your request packets should look like the requests of the browser.
I'm in the same scenario, I have to create a POST request to an external ASPX page.
I have captured the traffic using FIDDLER and tryed to simulare the call using online post request tool like https://www.codepunker.com
I have not been able to recreate the request...
In my opinion (and this require time) we have to:
Create a basic webrequest to the source form
Collect all the form elements with value
Create a POST request submitting all the elements including VIEWSTATE
NOTE: may be that you need to use a webclient that accepts cookies, check:
Accept Cookies in WebClient?
Good luck
I'm debugging my webserver, and I'd like to manually send HEAD requests to some web pages. Is there a way to do this in Firefox? Some extension perhaps.
I want to use firefox so that it can be part of a normal session (ie cookies set, logged in, etc). So things like curl aren't perfect.
Another possiblity is opening up firebug (or making this into a greasemonkey script) and using javascript to send your HEAD request.
// Added comments
var xmlhttp = new XmlHttpRequest();
xmlhttp.open("HEAD", "/test/this/page.php",true); // Make async HEAD request (must be a relative path to avoid cross-domain restrictions)
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) { // make sure the request is complete
alert(xmlhttp.getAllResponseHeaders()) // display the headers
}
}
xmlhttp.send(null); // send request
XmlHttpRequests inherit the cookies and current session (authentication from .htaccess etc).
Way to use this:
Use the javascript: url method
Use the Firebug console (http://getfirebug.com/) to execute javascript on the page
Create a greasemonkey script that executes HEAD requests and displays the result
Live HTTP Headers can send arbitrary HTTP requests using its replay function. Though it's a bit fiddly. And as it's a HEAD request, there'll be no output to see locally (it's normally displayed in the browser window).
First you need to open up the Live HTTP Headers (LHH) window, do your request from the browser using GET, then select that request in the LHH window and choose Replay.... Then, in the window that pops up, change GET to HEAD and fiddle with the headers if you like.
Pressing Replay will make the request.
This is a pretty old thread, but there is a firefox plugin called "Poster" that does what you want.
There is another plugin I've used called "Rest Client" that is also good.
I don't know of any plugin but this page might be of some use to you
http://www.askapache.com/online-tools/http-headers-tool
I believe that you can send head requests with Fiddler
http://www.fiddler2.com/Fiddler2/version.asp
This seems to be a solution that works in firefox as an addon, called Modify Headers
https://addons.mozilla.org/en-US/firefox/addon/967
Check out http-tool for firefox ..
https://addons.mozilla.org/en-US/firefox/addon/http-tool/
Aimed at web developers who need to debug HTTP requests and responses.
Can be extremely useful while developing REST based api.
Features:
* GET
* HEAD
* POST
* PUT
* DELETE
Add header(s) to request.
Add body content to request.
View header(s) in response.
View body content in response.
View status code of response.
View status text of response.