How's Vlang get a header request?



  • In the headline, it's been described.

    import net.http
    

    fn main() {
    url := 'http://212.183.159.230/10MB.zip'
    header := http.new_custom_header_from_map({'Range': 'bytes=0-10'})?
    res := // тут запрос
    }



  • import json
    import net.http
    
    
    fn main() {
        config := http.FetchConfig{
            header: http.new_header(key: 'Range', value: 'bytes=0-10')
        }
    
        url := 'http://212.183.159.230/10MB.zip'
    
        resp := http.fetch(http.FetchConfig{ ...config, url: url }) or {
            println('failed to fetch data from the server')
            return
        }
    
        mystruct := json.decode(MyStruct, resp.text) or {
            println('failed to decode MyStruct json')
            return
        }
    
        println(mystruct)
    }
    
    

    https://github.com/vlang/v/blob/master/examples/get_weather/get_weather.v
    https://github.com/vlang/v/blob/51d7aede68c2b3ac4b7db76c1d60741bb6db58a4/vlib/net/http/header_test.v


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2