ReactNativeUtil icon indicating copy to clipboard operation
ReactNativeUtil copied to clipboard

Webview 如何查看header头信息

Open wuyunqiang opened this issue 7 years ago • 0 comments

有时候使用webview需要查看发送的header信息是否正确发送,一般我们都是和后台配合来检验的。其实我们也可以自己来检验,自己启动一个node作为服务端,然后连接本地的node服务来查看header信息。

var http = require('http');
var port = 9000;

function logRequest(request) {
    console.log("request headers: ", request.headers)
    console.log("Processing request for: ", request.url)
    console.log('Time',new Date().toString())

}

http.createServer(function(request, response) {
    response.writeHead(200, {"Content-Type": "text/html"});
    switch(request.url) {
        case "/":
            response.write("<html><body>Welcome<a href='/bye'>Bye</a></body></html>");
            logRequest(request)
            break;
        case "/bye":
            response.write("<html><body>Bye<a href='/'>Welcome</a></body></html>");
            logRequest(request)
            break;
        default:
            break;
    }
    response.end();
}).listen(port);

1:新建js文件取名server.js 然后复制上面的代码 2:打开命令行 node ../../server.js(server.js 路径) 3:修改webview 的source路径 添加header信息

 source={{uri: "http://localhost:9000/", headers: {name:"wuyunqiang",do:"testing"}}}

4:正常运行应用 打开webview页面 命令行显示如下 7C5797FE-CC3E-402F-971F-632DB13C067B.png

wuyunqiang avatar May 24 '18 08:05 wuyunqiang