0

I have a PowerShell script to verify the existence of many (half a million) files in a web server. Some of these files are large (gigabytes) and I don't wan't to transfer them, so I've been using the HTTP HEAD method.

The problem is, today I found that the HTTP status code returned from the HEAD method may be different from the status returned by GET (which is always the correct one):

Using HEAD:

> Invoke-WebRequest -Method head http://example.com/82833749.mbtiles


StatusCode        : 200
StatusDescription : OK
Content           : {}
RawContent        : HTTP/1.1 200 OK
                    Content-MD5: LwIBDR5QRptNAE2Hdpu+aw==
                    x-ms-request-id: 774da565-101e-0053-7903-38e136000000
                    x-ms-version: 2009-09-19
                    x-ms-lease-status: unlocked
                    x-ms-blob-type: BlockBlob
                    Connect...
Headers           : {[Content-MD5, LwIBDR5QRptNAE2Hdpu+aw==], [x-ms-request-id, 
                    774da565-101e-0053-7903-38e136000000], [x-ms-version, 2009-09-19], [x-ms-lease-status, 
                    unlocked]...}
RawContentLength  : 0

With GET:

> Invoke-WebRequest http://example.com/82833749.mbtiles
Invoke-WebRequest : BlobNotFoundThe specified blob does not exist. RequestId:dede785b-b01e-0091-4b08-38a7b0000000 
Time:2022-03-15T01:02:36.7883837Z
No linha:1 caractere:1
+ Invoke-WebRequest http://example.com/82833749.mbtiles
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

> $Error[0].Exception.Response.StatusCode.value__
404

Right after running the GET request, the HEAD request will return the correct status code, making it more confusing to understand what is going on.

Rubén
  • 34,714
  • 9
  • 70
  • 166
Sarmat
  • 1
  • 2
    This is not a PowerShell issue, but more a problem with whichever service you're using. If you need to verify 500k files, and you're a paying customer, you should open a support case with them to look into it. They may also have a faster way to do this too. – FoxDeploy Mar 15 '22 at 02:00
  • There is no difference between a HTTP Request GET and HTTP HEAD in making a connection. The difference is in the server code. So you should contact the people who maintain the server. – jdweng Jan 21 '23 at 13:43

0 Answers0