I managed to find out what the problem is, so here:
Wireshark showed the following message between client and server:
WebRequest Case
DELETE /booster HTTP/1.1 Host: localhost:5984 Connection: Keep-Alive HTTP/1.1 302 Moved Temporarily Server: CouchDB/1.0.2 (Erlang OTP/R14B) Location: http://localhost:5984/_utils/session.html?return=%2Fbooster&reason=You%20are%20not%20a%20server%20admin. Date: Fri, 25 Nov 2011 09:54:29 GMT Content-Type: text/plain;charset=utf-8 Content-Length: 64 Cache-Control: must-revalidate {"error":"unauthorized","reason":"You are not a server admin."} DELETE /_utils/session.html?return=%2Fbooster&reason=You%20are%20not%20a%20server%20admin. HTTP/1.1 Host: localhost:5984 HTTP/1.1 405 Method Not Allowed Server: CouchDB/1.0.2 (Erlang OTP/R14B) Date: Fri, 25 Nov 2011 09:54:29 GMT Content-Type: text/plain;charset=utf-8 Content-Length: 64 Cache-Control: must-revalidate Allow: GET,HEAD {"error":"method_not_allowed","reason":"Only GET,HEAD allowed"}
Swirl Case
DELETE /booster HTTP/1.1 Authorization: Basic YWRtaW46MTIz User-Agent: curl/7.22.0 (i386-pc-win32) libcurl/7.22.0 OpenSSL/0.9.8r zlib/1.2.5 Host: localhost:5984 Accept: */* HTTP/1.1 404 Object Not Found Server: CouchDB/1.0.2 (Erlang OTP/R14B) Date: Fri, 25 Nov 2011 09:54:14 GMT Content-Type: text/plain;charset=utf-8 Content-Length: 41 Cache-Control: must-revalidate {"error":"not_found","reason":"missing"}
This shows that WebRequest does not use basic authorization, but curl uses it. A small number of search queries showed how to use basic authorization in WebRequest, and looks like this:
try { var request = WebRequest.Create("http://localhost:5984/booster"); request.Headers.Clear(); request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes("admin:123")); request.Method = "DELETE"; var response = request.GetResponse(); Console.WriteLine(response.GetResponseString()); } catch (WebException e) { Console.WriteLine(e.Response.GetResponseString()); }
source share