无法在Minitest中发送请求标头

 zhang时代小窝 发布于 2022-12-14 19:47

我正在尝试使用Minitest中的自定义标头发送请求:

get '/api/v1/tasks/all', nil, {:authorization => 'sdlfjkvnsdfljn'}

但由于某种原因,请求标头未被发送.这是价值request.headers.env:

"{"rack.version"=>[1, 2], "rack.input"=>#, "rack.errors"=>#, "rack.multithread"=>true, "rack.multiprocess"=>true, "rack.run_once"=>false, "REQUEST_METHOD"=>"GET", "SERVER_NAME"=>"example.org", "SERVER_PORT"=>"80", "QUERY_STRING"=>"", "PATH_INFO"=>"/api/v1/tasks/all", "rack.url_scheme"=>"http", "HTTPS"=>"off", "SCRIPT_NAME"=>"", "CONTENT_LENGTH"=>"0", "rack.test"=>true, "REMOTE_ADDR"=>"127.0.0.1", "HTTP_HOST"=>"example.org", "HTTP_COOKIE"=>"", "ORIGINAL_FULLPATH"=>"/api/v1/tasks/all", "ORIGINAL_SCRIPT_NAME"=>"", "action_dispatch.routes"=>#, "action_dispatch.parameter_filter"=>[:password], "action_dispatch.redirect_filter"=>[], "action_dispatch.secret_token"=>"21a9fdaa0b07f7e418e9a7c838e124fd1f3fbd2b65fb1520f8d38e10d643ce33cc46995f359bd38bfbc9335905fbdeb8af6879ebae131d3fe76f69a9619f6b37", "action_dispatch.secret_key_base"=>"a021d8b08999858216f202033b8124c4c8ec34590c3c62bec68e08e37526176c64d3d396b1e9109f74966b22056a65f557d6fd761093992d5641eb8a741bfc39", "action_dispatch.show_exceptions"=>false, "action_dispatch.show_detailed_exceptions"=>true, "action_dispatch.logger"=>#, @formatter=#, @logdev=#, @mutex=#>>>, "action_dispatch.backtrace_cleaner"=>#, #, #, #], @silencers=[#]>, "action_dispatch.key_generator"=>#, @cache_keys=#"\xD6Q\xF1\xD9\xA6w\x18\x80\xB1,\xE3\xB6\x8EQ\xC0'.-\xE5\xA3\x80$\xD8\xAD\xD8\n\xDD\x84\xCED\xE4q\xDA\xC8W\xB5\xE7m\xE8a\xC6\xD8\r\xA0\xA1Q\xC5ug\xD5R\x9C\x96\xE7vIZC\xAC\xEB\x92h\b\x89", "signed encrypted cookie64"=>" \xA2\xAF\t\xADr_\x1A\x87q\x00\xC0\x8DO2\xEF\x1ElZ5\xB6\xBAS\x9Em\x16crM\xEC\xC5\xEF\xD4\x8E\xDCC\xDB\xA5K\xE88\xCFl\x1F\x86\e\x99\xC0\xD0\xEF\xB9:\xAA\xE2Y\xB9h\xF3\xB4Mz\x9E] "}, @default_proc=nil>>, "action_dispatch.http_auth_salt"=>"http authentication", "action_dispatch.signed_cookie_salt"=>"signed cookie", "action_dispatch.encrypted_cookie_salt"=>"encrypted cookie", "action_dispatch.encrypted_signed_cookie_salt"=>"signed encrypted cookie", "action_dispatch.cookies_serializer"=>:json, "ROUTES_42736580_SCRIPT_NAME"=>"", "action_dispatch.request_id"=>"335f502d-c3be-44af-9463-89f75d6edc5a", "action_dispatch.remote_ip"=>#, "rack.session"=>#, "rack.session.options"=>#:user, :scope_defaults=>{}, :default_strategies=>{:user=>[:rememberable, :database_authenticatable]}, :intercept_401=>false, :failure_app=>#}, @app=#>, @cache_control="max-age=0, private, must-revalidate", @no_cache_control="no-cache">>>, @parsers={#=>:json}>>, @default_options={:path=>"/", :domain=>nil, :expire_after=>nil, :secure=>false, :httponly=>true, :defer=>false, :renew=>false}, @key="_bo_crmtronic_com_session", @cookie_only=true>, @env={...}, @delegate={:path=>"/", :domain=>nil, :expire_after=>nil, :secure=>false, :httponly=>true, :defer=>false, :renew=>false, :id=>nil}>, "warden"=>Warden::Proxy:44849780 @config={:default_scope=>:user, :scope_defaults=>{}, :default_strategies=>{:user=>[:rememberable, :database_authenticatable]}, :intercept_401=>false, :failure_app=>#}, "action_dispatch.request.path_parameters"=>{:format=>"json", :controller=>"api/v1/tasks", :action=>"all"}, "action_controller.instance"=>#"text/html"}, @_status=200, @_request=#"json", "controller"=>"api/v1/tasks", "action"=>"all"}, @filtered_env=nil, @filtered_path=nil, @protocol=nil, @port=nil, @method="GET", @request_method="GET", @remote_ip=nil, @original_fullpath=nil, @fullpath="/api/v1/tasks/all", @ip=nil, @uuid=nil>, @_response=#, @stream=#, @buf=[], @closed=false>, @header={"X-Frame-Options"=>"SAMEORIGIN", "X-XSS-Protection"=>"1; mode=block", "X-Content-Type-Options"=>"nosniff"}, @status=200, @sending_file=false, @blank=false, @cv=#, @cond=#>, @committed=false, @sending=false, @sent=false, @content_type=nil, @charset=nil, @cache_control={}, @etag=nil, @request=#"json", "controller"=>"api/v1/tasks", "action"=>"all"}, @filtered_env=nil, @filtered_path=nil, @protocol=nil, @port=nil, @method="GET", @request_method="GET", @remote_ip=nil, @original_fullpath=nil, @fullpath="/api/v1/tasks/all", @ip=nil, @uuid=nil>>, @_env={...}, @_prefixes=["api/v1/tasks", "application"], @_lookup_context=#[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}, @skip_default_locale=false, @cache=true, @prefixes=["api/v1/tasks", "application"], @rendered_format=nil, @view_paths=#>>, @path="/home/sergey/Desktop/git2/bo.crmtronic.com/app/views">, #>>, @path="/home/sergey/.rvm/gems/ruby-2.1.2/gems/devise-3.2.4/app/views">]>>, @_action_name="all", @_response_body=nil, @marked_for_same_origin_verification=true, @_config={}, @_params={"format"=>"json", "controller"=>"api/v1/tasks", "action"=>"all"}>, "action_dispatch.request.content_type"=>nil, "action_dispatch.request.request_parameters"=>{}, "rack.request.query_string"=>"", "rack.request.query_hash"=>{}, "action_dispatch.request.query_parameters"=>{}, "action_dispatch.request.parameters"=>{"format"=>"json", "controller"=>"api/v1/tasks", "action"=>"all"}, "action_dispatch.request.formats"=>[#], "rack.request.cookie_hash"=>{}, "rack.request.cookie_string"=>"", "action_dispatch.cookies"=>#, @cache_keys=#"\xD6Q\xF1\xD9\xA6w\x18\x80\xB1,\xE3\xB6\x8EQ\xC0'.-\xE5\xA3\x80$\xD8\xAD\xD8\n\xDD\x84\xCED\xE4q\xDA\xC8W\xB5\xE7m\xE8a\xC6\xD8\r\xA0\xA1Q\xC5ug\xD5R\x9C\x96\xE7vIZC\xAC\xEB\x92h\b\x89", "signed encrypted cookie64"=>" \xA2\xAF\t\xADr_\x1A\x87q\x00\xC0\x8DO2\xEF\x1ElZ5\xB6\xBAS\x9Em\x16crM\xEC\xC5\xEF\xD4\x8E\xDCC\xDB\xA5K\xE88\xCFl\x1F\x86\e\x99\xC0\xD0\xEF\xB9:\xAA\xE2Y\xB9h\xF3\xB4Mz\x9E] "}, @default_proc=nil>>, @set_cookies={"request_method"=>{:value=>"GET", :path=>"/"}}, @delete_cookies={}, @host="example.org", @secure=false, @options={:signed_cookie_salt=>"signed cookie", :encrypted_cookie_salt=>"encrypted cookie", :encrypted_signed_cookie_salt=>"signed encrypted cookie", :secret_token=>"21a9fdaa0b07f7e418e9a7c838e124fd1f3fbd2b65fb1520f8d38e10d643ce33cc46995f359bd38bfbc9335905fbdeb8af6879ebae131d3fe76f69a9619f6b37", :secret_key_base=>"a021d8b08999858216f202033b8124c4c8ec34590c3c62bec68e08e37526176c64d3d396b1e9109f74966b22056a65f557d6fd761093992d5641eb8a741bfc39", :upgrade_legacy_signed_cookies=>true, :serializer=>:json}, @cookies={"request_method"=>"GET"}, @committed=false, @encrypted=#, @options={:signed_cookie_salt=>"signed cookie", :encrypted_cookie_salt=>"encrypted cookie", :encrypted_signed_cookie_salt=>"signed encrypted cookie", :secret_token=>"21a9fdaa0b07f7e418e9a7c838e124fd1f3fbd2b65fb1520f8d38e10d643ce33cc46995f359bd38bfbc9335905fbdeb8af6879ebae131d3fe76f69a9619f6b37", :secret_key_base=>"a021d8b08999858216f202033b8124c4c8ec34590c3c62bec68e08e37526176c64d3d396b1e9109f74966b22056a65f557d6fd761093992d5641eb8a741bfc39", :upgrade_legacy_signed_cookies=>true, :serializer=>:json}, @encryptor=#, @serializer=ActionDispatch::Cookies::NullSerializer>, @legacy_verifier=#>, @signed_or_encrypted=#, @options={:signed_cookie_salt=>"signed cookie", :encrypted_cookie_salt=>"encrypted cookie", :encrypted_signed_cookie_salt=>"signed encrypted cookie", :secret_token=>"21a9fdaa0b07f7e418e9a7c838e124fd1f3fbd2b65fb1520f8d38e10d643ce33cc46995f359bd38bfbc9335905fbdeb8af6879ebae131d3fe76f69a9619f6b37", :secret_key_base=>"a021d8b08999858216f202033b8124c4c8ec34590c3c62bec68e08e37526176c64d3d396b1e9109f74966b22056a65f557d6fd761093992d5641eb8a741bfc39", :upgrade_legacy_signed_cookies=>true, :serializer=>:json}, @encryptor=#, @serializer=ActionDispatch::Cookies::NullSerializer>, @legacy_verifier=#>>, "action_dispatch.request.unsigned_session_cookie"=>{}}"

如何在Minitest中发送请求标头?

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有