我可以使用curl向browsermob发送请求,如下所示:
curl -X PUT -d "pageRef=car" localhost:9000/proxy/8081/har/pageRef
。但是,我想使用请求模块在nodejs中执行此操作。使用请求模块的等效命令是什么?我认为它类似于request.put(url, data, callback)
,但当我尝试request.put('localhost:9000/proxy/8081/har/pageRef', {form: { pageRef: encodeURI(browser.platform) + encodeURI(browser.browserName) + encodeURI(browser.version) }})
时,我得到了
Error: Invalid protocol
at Request.self._buildRequest (/Users/dragonite/Pixel/node_modules/request/request.js:336:53)
at Request.init (/Users/dragonite/Pixel/node_modules/request/request.js:503:10)
at new Request (/Users/dragonite/Pixel/node_modules/request/request.js:97:8)
at request (/Users/dragonite/Pixel/node_modules/request/index.js:50:11)
at Function.request.put (/Users/dragonite/Pixel/node_modules/request/index.js:121:27)
at repl:1:10
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.emit (events.js:95:17)
at Interface._onLine (readline.js:203:10)
答案 0 :(得分:1)
看起来你只是错过了网址前的协议,如:
request.put('http://localhost:9000/proxy/8081/har/pageRef', {form: { pageRef: encodeURI(browser.platform) + encodeURI(browser.browserName) + encodeURI(browser.version) }})