dongshuxi3105 2018-06-16 09:48
浏览 73
已采纳

将请求发送到Https站点

Essentially, through goLang I'm trying to send a request on a https site to check if an item is on the site. I have tried to attempt a request to the main site, but keep getting access denied and need a way to tackle this, I'm trying to get the info from the body to separate it and find the correct ids to check if something is on the site.

package main

import (
    "fmt"
    "net/http"
    "io/ioutil"
)

func main() {

   url := "https://www.jdsports.co.uk/"

   req, _ := http.NewRequest("GET", url, nil)

   res, _ := http.DefaultClient.Do(req)

   defer res.Body.Close()

   body, _ := ioutil.ReadAll(res.Body)

   fmt.Println(string(body)) 
}
  • 写回答

1条回答 默认 最新

  • duanbi6522 2018-06-16 17:46
    关注

    After testing a little bit, it looks like that specific website is using Akamai Ghost and has been configured to block the default go http package user agent.

    The default user agent appears to be Go-http-client/1.1

    If you change your user agent

    req.Header.Set("User-Agent", "my-client-app")
    

    The request will work. However, the website in question appears to not want to be programatically crawled. Perhaps you should respect their wishes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭