Forum Discussion

michal_blazek's avatar
michal_blazek
Regular Visitor
8 years ago

Status code checker - 404, 200, 301, 302

Hi,

please can anybody hlep me, hot to get 301 or 302 status of web urls? I have found this custom function:

(urlToCheck as text)=>

let

    Source = Value.Metadata(Web.Contents(urlToCheck, [ManualStatusHandling={404,200}]))[Response.Status]

in

    Source

But this shows me only 200 and 404 results, not redirections (301 + 302) and of course it does not work, when I write theese numbers between brackets.

Probably it is easy, but I do not know, how to write it...
https://github.com/Microsoft/DataConnectors/blob/master/docs/other-topics.md

THX to everybody for replay :-)

2 Replies

    • michal_blazek's avatar
      michal_blazek
      Regular Visitor

      Hi v-chuncz-msft,

      but this field only define, which part from metadata I have to chcek. When I define it without "ManualStatusHandling" and without [Response.Status], I got whole metadata table (record):

      • Content.Type (everytime: text/html)
      • Content.Uri (everytime: Function)
      • Content.Name (original not redirected URL)
      • Headers (after expanding record: everytime: text/html; charset=UTF-8)
      • Request.Option (everytime null)
      • Response.Status (everytime final response = 200 / 404)

      Problem is that by this setting I everytime got on the "final" page = "final" response. So I do not have the info about 301 / 302, but info from final page with final response (and it is 200). I'd like to know, which url's are 301 or 302 and in ideal way, what is the final redirection. Do you understand me?

      let
          Source= Excel.CurrentWorkbook(){[Name="Table"]}[Content],
          #"Change type" = Table.TransformColumnTypes(Source,{{"url", type text}}),
          #"Add metadata content" = Table.AddColumn(#"Change type", "new", each Value.Metadata(Web.Contents([url]))),
          #"Expand metadata" = Table.ExpandRecordColumn(#"Add metadata content", "new", {"Content.Type", "Content.Uri", "Content.Name", "Headers", "Request.Options", "Response.Status"}, {"Content.Type", "Content.Uri", "Content.Name", "Headers", "Request.Options", "Response.Status"}),
          #"Expand Headers" = Table.ExpandRecordColumn(#"Expand metadata", "Headers", {"Content-Type"}, {"Content-Type"})
      in
          #"Expand Headers"



      THX a lot.