“Socket hang up” error during request

后端 未结 7 690
北海茫月
北海茫月 2020-12-16 11:23

I try to make a GET request to some site (not mine own site) via http module of node.js version 0.8.14. Here is my code (CoffeeScript):

options = 
        ho         


        
相关标签:
7条回答
  • 2020-12-16 11:45

    I've finally detected the problem and found out the solution. The problem was that I use a proxy server to connect to the internet. Here is the working code:

    options = 
        hostname: 'myproxy.ru'
        path: 'http://www.ya.ru'
        port: 3128
        headers: {
            Host: "www.ya.ru"
        }
    req = http.request options, (res) ->
        output = ''
        console.log 'STATUS: ' + res.statusCode
        res.on 'data', (chunk) ->
            console.log 'A new chunk: ', chunk
            output += chunk
    
        res.on 'end', () ->
            console.log output
            console.log 'End GET Request'
    
    req.on 'error', (err) ->
        console.log 'Error: ', err
    req.end()
    

    Thank you all for helps and suggestions!

    0 讨论(0)
提交回复
热议问题