GithubHelp home page GithubHelp logo

Comments (14)

tomas avatar tomas commented on July 19, 2024

I don't think I understood your question. Can you show the code your using?

from needle.

atian25 avatar atian25 commented on July 19, 2024

I means when use this module to download some url with charset=utf-8 , such as www.baidu.com,
the chinese words is unreadable.

and I saw other module use iconv-lite to encode, or provide a stream method to allow user to encode buffer.

from needle.

tomas avatar tomas commented on July 19, 2024

Ok, got it. Can you show an example of how iconv-lite is used? I'd be happy to merge it into the codebase.

from needle.

atian25 avatar atian25 commented on July 19, 2024

https://github.com/andris9/fetch/issues/4
https://github.com/ashtuchkin/iconv-lite

from needle.

tomas avatar tomas commented on July 19, 2024

Ok, looks simple, but it seems we'd need to pass a buffer to iconv.decode() and Needle currently handles hte response as a plain string. I just pushed a commit that grabs the charset from the content type header, but if possible I'd like you to fork and make a pull request, to make sure we get it right (I can only say Ni-hao in chinese, to start). :)

from needle.

tomas avatar tomas commented on July 19, 2024

Ok, just pushed a new brach called iconv and though everything looks right, I just cant get the same output for baidu.com as returned by cURL. Any pointers?

from needle.

atian25 avatar atian25 commented on July 19, 2024

hi, I had check out the iconv branch and test, everything is ok now, thanks

from needle.

tomas avatar tomas commented on July 19, 2024

Are you sure? The version I get of baidu.com is slightly different from the one I get via cURL.

from needle.

atian25 avatar atian25 commented on July 19, 2024

env

  • win7
  • chinese
  • cmd encoding is gbk
  • node v0.8.7

target:

step1:

  • use master branch code, change the test.js#simple_get to www.baidu.com
  • output :
    <title>�ٶ�һ�£�����֪��      </title>
    

step2:

  • use iconv branch code, change the test.js#simple_get to www.baidu.com
  • output :
    <title>百度一下,你就知道      </title>
    

another bug

  • when use icon branch, simple_get http://www.baidu.com/home/show/home
  • error:
    
    E:\Workspace\Git\needle>node test/test.js get
    E:\Workspace\Git\needle\lib\needle.js:151
          charset = header && header[1].replace('charset=', '').trim();
                                        ^
    TypeError: Cannot call method 'replace' of undefined
    at ClientRequest. (E:\Workspace\Git\needle\lib\needle.js:151:41)
    at ClientRequest.g (events.js:185:14)
    at ClientRequest.EventEmitter.emit (events.js:88:17)
    at HTTPParser.parserOnIncomingClient [as onIncoming](http.js:1455:7)
    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete](http.js:111:23)
    at Socket.socketOnData [as ondata](http.js:1366:20)
    at TCP.onread (net.js:402:27)
    
    

from needle.

tomas avatar tomas commented on July 19, 2024

Fixed! Try again and see if it works. :)

from needle.

atian25 avatar atian25 commented on July 19, 2024

yes, works.
I hate redirect by location.href ... which can't follow by code.


    E:\Workspace\Git\needle>node test\test.js get
    null
    Got status code 200
   <script>
    location.href="http://www.baidu.com/";
   </script>

from needle.

atian25 avatar atian25 commented on July 19, 2024

when will this publish to npm?

from needle.

tomas avatar tomas commented on July 19, 2024

Soon! I'll be out of the office all day tomorrow. :(

from needle.

monolithed avatar monolithed commented on July 19, 2024

Have the same problem
Solved:

needle.post(URL, { 'mode': '1' }, { decode: false }, function () {})

from needle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.