http

301 Redirects for dead links

I'm migrating a client from a proprietary system to a wordpress CMS-type platform. His old site has years of indexed pages on Google. I'm already using pretty URL's in Wordpress, but I can't replicate the structure exactly and migrate over the pages maintaining the URL. We'd like to issue a proper HTTP 301 header to the new residence...

How to catch 404 error in urllib.urlretrieve

Background: I am using urllib.urlretrieve, as opposed to any other function in the urllib* modules, because of the hook function support (see reporthook below) .. which is used to display a textual progress bar. This is Python >=2.6. >>> urllib.urlretrieve(url[, filename[, reporthook[, data]]]) However, urlretrieve is so dumb that it ...

Is it possible to peek at the data in a urllib2 response?

I need to detect character encoding in HTTP responses. To do this I look at the headers, then if it's not set in the content-type header I have to peek at the response and look for a "<meta http-equiv='content-type'>" header. I'd like to be able to write a function that looks and works something like this: response = urllib2.urlopen("...

Writing the interface to a web service API

I'm beginning to design a web-based API and the very first issue—how will users interact with it—left me at a loss. This is an API that is only going to be used by other folks within our company and will be used by people who have some programming knowledge, so there's a good bit of leeway in all respects, and it needn't be simple enoug...

How to do basic authentication with Prowser using e-mail address-based usernames?

I am using Prowser to screen scrape internal corporate websites. Some of the sites use basic authentication where the username is: [email protected] According to the documentation, in order to user digest or basic auth, I need to open the URL like this: https://username:[email protected]/ But when I actually construct the URL, it lo...

Downloading compressed content over HTTP using Python

How do I take advantage of HTTP 1.1's compression when downloading web pages using Python? I am currently using the built-in urllib module for downloading web content. Reading through the documentation I couldn't find any information that is indeed using compression. Is it already built-in into urllib or is there another library that ...

Simple comet example using php and jquery

I have searched on google for hours without finding a good and simple example of the comet technique using PHP. I just need an example that uses a persistent HTTP connection or something similar. I dont want to use a polling technique because I have something like that set up and not only is it difficult to work with and manage its a big...

Canonical vs Requested Type in Content Negotation

So I was wondering what should be done with HTTP Content Negotiation regarding requests where the returned data may have multiple valid MIME types. For example if say I have some arbitrary data that has the following possible MIME types: text/data,application/x-data,application/data+xml Given that there are multiple MIME types possib...

POSTing data programatically

I want to programatically download the contents of a web page, but that page is generated as the result of a POST and I cant seem to get it working. This is the page: http://jp.translink.com.au/mobile/Input.aspx You can enter the following values to see how it works: From: Coorparoo Railway Station To: Central Railway Station I have...

What is the best Java library to use for HTTP POST, GET etc.?

What is the best Java library to use for HTTP POST, GET etc. in terms of performance, stability, maturity etc.? Is there one particular library that is used more than others? My requirements are submitting HTTPS POST requests to a remote server. I have used the java.net.* package in the past as well as org.apache.commons.httpclient.* pa...

Mobile Devices get HTTP 504 Error

I am trying to debug why a mobile device trying to connect to my embedded web server is getting a "HTTP 504 Error: Gateway timeout". A PC can connect just fine, it's just the Blackberries and mobile phones that get this error. What does a 504 error mean? What can I do about it? ...

Collections, items, verbs and REST interface design: what should POSTs return?

I'm designing a REST interface and I'm puzzled by what should the insert/update/delete verb return (as content of the response). Consider an inteface for Invoice entities, accessible at api/invoices: GET /api/invoices returns a list of invoices GET /api/invoices/123 returns the invoice with ID 123 POST /api/invoices adds a new ...

Is there a HTTP header field / hack to tell the browser NOT to pipeline its requests ?

I am implementing a minimalistic web server application on a Microcontroller. When I have several images (or CSS/JS) on the web page, the browser creates several connections and fetches them. But the Microcontroller can not catch up with this. Is there a way to tell the browser to stop pipelining and fetch them one by one ? Note :: "Con...

Is persistent HTTP with HTTP/1.0 possible?

I am using a 3G UMTS connection. I am trying to implement HTTP tunneling to a server of mine which listens on port 80 (this is done in order to bypass client's firewall). The problem is that the ISP's proxy server supports HTTP/1.0 which doesn't support persistent HTTP connection. As a result, after one http request/response iteration...

How to REDIRECT a web Page for every ten seconds

In simple there is any way to redirect a page for every ten seconds in PHP ...

REST: Keeping track after the back button

I want to write a web app order system using the REST methodology for the first time. I understand the concept of the "message id" when things get posted to a page but this scenario comes up. Once a user posts to the web app, you can keep track of their state with an id attached to the URI but what happens if they hit the back button of ...

Cookies across multiple WAR files

I'm creating a facelets template for all my company's internal applications. Its appearance is based on the skin which the user selects (like gmail themes). It makes sense to store the user's preferred skin in a cookie. My "user-preferences" WAR can see this cookie. However, my other applications are unable to find the cookie. They a...

To inform users of denied access, is it better to redirect to a different page/document using HTTP headers or is it best to incorporate a message in the dynamic page?

I would like to know what is the best practice for informing a user that their access attempt was denied. I realize there are probably more options, but these are the methods I'm considering: Inform a user on a dedicated "Access Denied" page reached when my script redirects them via header("Location:") Inform a user in message in the r...

Use https only for certain pages in tomcat webapp

Hello, I have a struts2 webapp running under tomcat6 app server. The mode is https. The entire site is currently being served on https. But what I would really like to do is setup https only for certain operations like purchase and login. Is there any configuration in tomcat that can help me do this easily? Are there any code changes r...

Getting Http Status code number (200, 301, 404, etc.) from HttpWebRequest and HttpWebResponse

I am trying to get the HTTP status code number from the HttpWebResponse object returned from a HttpWebRequest. I was hoping to get the actual numbers (200, 301,302, 404, etc.) rather than the text description. ("Ok", "MovedPermanently", etc.) Is the number buried in a property somewhere in the response object? Any ideas other than cr...