当我使用JSON主体向我的REST服务发出POST请求时,我将其包含Content-type: application/json; charset=utf-8在邮件头中.没有这个标题,我从服务中得到一个错误.我也可以成功使用Content-type: application/json没有;charset=utf-8部分.
到底是charset=utf-8做什么的?我知道它指定了字符编码,但没有它,服务工作正常.此编码是否限制可以在邮件正文中的字符?
用Nokogiri解析HTTP响应
嗨,我在使用Nokogiri解析HTTPresponse对象时遇到问题.
我用这个函数在这里获取一个网站:
def fetch(uri_str, limit = 10)
# You should choose better exception.
raise ArgumentError, 'HTTP redirect too deep' if limit == 0
url = URI.parse(URI.encode(uri_str.strip))
puts url
#get path
req = Net::HTTP::Get.new(url.path,headers)
#start TCP/IP
response = Net::HTTP.start(url.host,url.port) { |http|
http.request(req)
}
case response
when Net::HTTPSuccess
then #print final redirect to a file
puts "this is location" + uri_str
puts "this is the host #{url.host}"
puts "this is the path #{url.path}"
return response
# if you get a …Run Code Online (Sandbox Code Playgroud)