首页 头条 财经 产业 金融 电商 跨境 物流 会展 English
首页 / 网购优选 / 正文

被服务器拒绝请求常出现415 unsupported media type

来源:
编辑:电经淘讯
时间:2023-09-04

通常有以下情况:
      1:检查你的http请求头信息,比如因为 User-Agent 被服务器设置拒绝请求了;比如你写的的爬虫,就很有可能因为没有伪装成浏览器,被拒绝请求。
      2:查看你的 http 请求方法,以及服务器端的设置。比如:有一个 强制用 post 请求的接口,你是不是用了非post 请求。
      3:post 请求参数设置,是不是必须的,json 格式。比如下面,两段代码,
      如下 json参数,body


 import requests
      import json
      payload={"userName":"names","userCode":"123456","phoneNum":"7800","regPic":"picData"}
      headers={'content-type': 'application/json'}
      burl="http://httpbin.org/post"
      r=requests.post(burl, data=json.dumps(payload), headers=headers)
      print r.text
      如下 form 格式 参数
      import requests
      import json
      payload={"userName":"names","userCode":"123456","phoneNum":"7800","regPic":"picData"}
      headers={'content-type': 'application/json'}
      burl="http://httpbin.org/post"
      r=requests.post(burl, data=payload, headers=headers)
      print r.text

电经快报更多
经济视界更多

听故事、领福利、玩新招—AppGallery「

鸿蒙5应用市场AppGallery“夏日追光计划”带着第二...[详细]

“吨级商载+百米起降” 昂际智航与翊飞

近日,昂际智航与翊飞航空科技在首届国际低空经济博览会上,正式...[详细]

热点财经更多
  • CopyRight @ 2013-2025 Reserved CN电商经济网版权所有所涉内容免责声明查阅